diff options
author | Raphael Isemann <teemperor@gmail.com> | 2018-07-12 22:28:52 +0000 |
---|---|---|
committer | Raphael Isemann <teemperor@gmail.com> | 2018-07-12 22:28:52 +0000 |
commit | 4d51a90297d34389b53c00c5cd6fa6f73998c298 (patch) | |
tree | fb8d42ce62a2a5e7bff1c397626c774ce51e3fee /lldb/source/Interpreter/CommandObjectRegexCommand.cpp | |
parent | 3a1347721454c50c0f06cdf99388b8d38a49c408 (diff) | |
download | bcm5719-llvm-4d51a90297d34389b53c00c5cd6fa6f73998c298.tar.gz bcm5719-llvm-4d51a90297d34389b53c00c5cd6fa6f73998c298.zip |
Get rid of the C-string parameter in DoExecute
Summary:
This patch gets rid of the C-string parameter in the RawCommandObject::DoExecute function,
making the code simpler and less memory unsafe.
There seems to be a assumption in some command objects that this parameter could be a nullptr,
but from what I can see the rest of the API doesn't actually allow this (and other command
objects and related code pieces dereference this parameter without any checks).
Especially CommandObjectRegexCommand has error handling code for a nullptr that is now gone.
Reviewers: davide, jingham, teemperor
Reviewed By: teemperor
Subscribers: jingham, lldb-commits
Differential Revision: https://reviews.llvm.org/D49207
llvm-svn: 336955
Diffstat (limited to 'lldb/source/Interpreter/CommandObjectRegexCommand.cpp')
-rw-r--r-- | lldb/source/Interpreter/CommandObjectRegexCommand.cpp | 72 |
1 files changed, 33 insertions, 39 deletions
diff --git a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp index 6826a2c334f..a5362c3729b 100644 --- a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp +++ b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp @@ -35,53 +35,47 @@ CommandObjectRegexCommand::CommandObjectRegexCommand( //---------------------------------------------------------------------- CommandObjectRegexCommand::~CommandObjectRegexCommand() {} -bool CommandObjectRegexCommand::DoExecute(const char *command, +bool CommandObjectRegexCommand::DoExecute(llvm::StringRef command, CommandReturnObject &result) { - if (command) { - EntryCollection::const_iterator pos, end = m_entries.end(); - for (pos = m_entries.begin(); pos != end; ++pos) { - RegularExpression::Match regex_match(m_max_matches); + EntryCollection::const_iterator pos, end = m_entries.end(); + for (pos = m_entries.begin(); pos != end; ++pos) { + RegularExpression::Match regex_match(m_max_matches); - if (pos->regex.Execute(command, ®ex_match)) { - std::string new_command(pos->command); - std::string match_str; - char percent_var[8]; - size_t idx, percent_var_idx; - for (uint32_t match_idx = 1; match_idx <= m_max_matches; ++match_idx) { - if (regex_match.GetMatchAtIndex(command, match_idx, match_str)) { - const int percent_var_len = - ::snprintf(percent_var, sizeof(percent_var), "%%%u", match_idx); - for (idx = 0; (percent_var_idx = new_command.find( - percent_var, idx)) != std::string::npos;) { - new_command.erase(percent_var_idx, percent_var_len); - new_command.insert(percent_var_idx, match_str); - idx += percent_var_idx + match_str.size(); - } + if (pos->regex.Execute(command, ®ex_match)) { + std::string new_command(pos->command); + std::string match_str; + char percent_var[8]; + size_t idx, percent_var_idx; + for (uint32_t match_idx = 1; match_idx <= m_max_matches; ++match_idx) { + if (regex_match.GetMatchAtIndex(command, match_idx, match_str)) { + const int percent_var_len = + ::snprintf(percent_var, sizeof(percent_var), "%%%u", match_idx); + for (idx = 0; (percent_var_idx = new_command.find( + percent_var, idx)) != std::string::npos;) { + new_command.erase(percent_var_idx, percent_var_len); + new_command.insert(percent_var_idx, match_str); + idx += percent_var_idx + match_str.size(); } } - // Interpret the new command and return this as the result! - if (m_interpreter.GetExpandRegexAliases()) - result.GetOutputStream().Printf("%s\n", new_command.c_str()); - // Pass in true for "no context switching". The command that called us - // should have set up the context appropriately, we shouldn't have to - // redo that. - return m_interpreter.HandleCommand(new_command.c_str(), - eLazyBoolCalculate, result, nullptr, - true, true); } + // Interpret the new command and return this as the result! + if (m_interpreter.GetExpandRegexAliases()) + result.GetOutputStream().Printf("%s\n", new_command.c_str()); + // Pass in true for "no context switching". The command that called us + // should have set up the context appropriately, we shouldn't have to + // redo that. + return m_interpreter.HandleCommand( + new_command.c_str(), eLazyBoolCalculate, result, nullptr, true, true); } - result.SetStatus(eReturnStatusFailed); - if (!GetSyntax().empty()) - result.AppendError(GetSyntax()); - else - result.AppendErrorWithFormat("Command contents '%s' failed to match any " - "regular expression in the '%s' regex " - "command.\n", - command, m_cmd_name.c_str()); - return false; } - result.AppendError("empty command passed to regular expression command"); result.SetStatus(eReturnStatusFailed); + if (!GetSyntax().empty()) + result.AppendError(GetSyntax()); + else + result.GetOutputStream() << "Command contents '" << command + << "' failed to match any " + "regular expression in the '" + << m_cmd_name << "' regex "; return false; } |