From 4d51a90297d34389b53c00c5cd6fa6f73998c298 Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Thu, 12 Jul 2018 22:28:52 +0000 Subject: 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 --- lldb/source/Commands/CommandObjectExpression.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lldb/source/Commands/CommandObjectExpression.cpp') diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index 9373813b8d0..08959ff8473 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -318,7 +318,7 @@ CanBeUsedForElementCountPrinting(ValueObject &valobj) { return Status(); } -bool CommandObjectExpression::EvaluateExpression(const char *expr, +bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr, Stream *output_stream, Stream *error_stream, CommandReturnObject *result) { @@ -508,19 +508,19 @@ void CommandObjectExpression::GetMultilineExpression() { debugger.PushIOHandler(io_handler_sp); } -bool CommandObjectExpression::DoExecute(const char *command, +bool CommandObjectExpression::DoExecute(llvm::StringRef command, CommandReturnObject &result) { m_fixed_expression.clear(); auto exe_ctx = GetCommandInterpreter().GetExecutionContext(); m_option_group.NotifyOptionParsingStarting(&exe_ctx); - if (command[0] == '\0') { + if (command.empty()) { GetMultilineExpression(); return result.Succeeded(); } OptionsWithRaw args(command); - const char *expr = args.GetRawPart().c_str(); + llvm::StringRef expr = args.GetRawPart(); if (args.HasArgs()) { if (!ParseOptionsAndNotify(args.GetArgs(), result, m_option_group, exe_ctx)) @@ -584,7 +584,7 @@ bool CommandObjectExpression::DoExecute(const char *command, } } // No expression following options - else if (expr[0] == '\0') { + else if (expr.empty()) { GetMultilineExpression(); return result.Succeeded(); } -- cgit v1.2.3