[Lldb-commits] [PATCH] D120101: [lldb] Fix (unintentional) recursion in CommandObjectRegexCommand
Med Ismail Bennani via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Thu Feb 17 17:06:50 PST 2022
mib added inline comments.
================
Comment at: lldb/source/Commands/CommandObjectRegexCommand.cpp:38
+ // Parse the number following '%'.
+ const size_t idx = std::atoi(str.c_str() + pos + 1);
+
----------------
Are we assuming that the number following `%` will always have a single digit ?
================
Comment at: lldb/source/Commands/CommandObjectRegexCommand.cpp:50
+ const std::string replacement(replacements[idx]);
+ const size_t pattern_size = 1 + static_cast<size_t>(log10(idx) + 1);
+ str.replace(pos, pattern_size, replacement);
----------------
TIL but I think the exact formula is `floor(log10(num))+2` according to this https://stackoverflow.com/questions/61707231/why-is-log-base-10-used-in-this-code-to-convert-int-to-string
I don't know if this formula has a name but if it does it would be great to add it as a comment above.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D120101/new/
https://reviews.llvm.org/D120101
More information about the lldb-commits
mailing list