Skip to content

Commit

Permalink
Fix Clang-tidy readability-redundant-string-cstr warnings
Browse files Browse the repository at this point in the history
Reviewers: zturner, labath

Subscribers: tberghammer, danalbert, lldb-commits
    
Differential Revision: https://reviews.llvm.org/D26233

llvm-svn: 285855
  • Loading branch information
pepsiman committed Nov 2, 2016
1 parent 7463ada commit 771ef6d
Show file tree
Hide file tree
Showing 76 changed files with 163 additions and 181 deletions.
2 changes: 1 addition & 1 deletion lldb/source/Breakpoint/BreakpointResolverAddress.cpp
Expand Up @@ -66,7 +66,7 @@ BreakpointResolver *BreakpointResolverAddress::CreateFromStructuredData(
error.SetErrorString("BRA::CFSD: Couldn't read module name entry.");
return nullptr;
}
module_filespec.SetFile(module_name.c_str(), false);
module_filespec.SetFile(module_name, false);
}
return new BreakpointResolverAddress(bkpt, address, module_filespec);
}
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
Expand Up @@ -83,7 +83,7 @@ BreakpointResolver *BreakpointResolverFileLine::CreateFromStructuredData(
return nullptr;
}

FileSpec file_spec(filename.c_str(), false);
FileSpec file_spec(filename, false);

return new BreakpointResolverFileLine(bkpt, file_spec, line_no, offset,
check_inlines, skip_prologue,
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Commands/CommandCompletions.cpp
Expand Up @@ -414,7 +414,7 @@ CommandCompletions::SourceFileCompleter::SourceFileCompleter(
match_start_point, max_return_elements,
matches),
m_include_support_files(include_support_files), m_matching_files() {
FileSpec partial_spec(m_completion_str.c_str(), false);
FileSpec partial_spec(m_completion_str, false);
m_file_name = partial_spec.GetFilename().GetCString();
m_dir_name = partial_spec.GetDirectory().GetCString();
}
Expand Down Expand Up @@ -560,7 +560,7 @@ CommandCompletions::ModuleCompleter::ModuleCompleter(
: CommandCompletions::Completer(interpreter, completion_str,
match_start_point, max_return_elements,
matches) {
FileSpec partial_spec(m_completion_str.c_str(), false);
FileSpec partial_spec(m_completion_str, false);
m_file_name = partial_spec.GetFilename().GetCString();
m_dir_name = partial_spec.GetDirectory().GetCString();
}
Expand Down
3 changes: 1 addition & 2 deletions lldb/source/Commands/CommandObjectBreakpoint.cpp
Expand Up @@ -2305,8 +2305,7 @@ class CommandObjectBreakpointWrite : public CommandObjectParsed {
}
}
Error error = target->SerializeBreakpointsToFile(
FileSpec(m_options.m_filename.c_str(), true), valid_bp_ids,
m_options.m_append);
FileSpec(m_options.m_filename, true), valid_bp_ids, m_options.m_append);
if (!error.Success()) {
result.AppendErrorWithFormat("error serializing breakpoints: %s.",
error.AsCString());
Expand Down
14 changes: 7 additions & 7 deletions lldb/source/Commands/CommandObjectCommands.cpp
Expand Up @@ -635,7 +635,7 @@ rather than using a positional placeholder:"
}

// Verify that the command is alias-able.
if (m_interpreter.CommandExists(alias_command.c_str())) {
if (m_interpreter.CommandExists(alias_command)) {
result.AppendErrorWithFormat(
"'%s' is a permanent debugger command and cannot be redefined.\n",
alias_command.c_str());
Expand Down Expand Up @@ -728,7 +728,7 @@ rather than using a positional placeholder:"
// Verify that the command is alias'able, and get the appropriate command
// object.

if (m_interpreter.CommandExists(alias_command.c_str())) {
if (m_interpreter.CommandExists(alias_command)) {
result.AppendErrorWithFormat(
"'%s' is a permanent debugger command and cannot be redefined.\n",
alias_command.c_str());
Expand Down Expand Up @@ -780,17 +780,17 @@ rather than using a positional placeholder:"
args.GetCommandString(args_string);
}

if (m_interpreter.AliasExists(alias_command.c_str()) ||
m_interpreter.UserCommandExists(alias_command.c_str())) {
if (m_interpreter.AliasExists(alias_command) ||
m_interpreter.UserCommandExists(alias_command)) {
result.AppendWarningWithFormat(
"Overwriting existing definition for '%s'.\n",
alias_command.c_str());
}

if (CommandAlias *alias = m_interpreter.AddAlias(
alias_command.c_str(),
alias_command,
use_subcommand ? subcommand_obj_sp : command_obj_sp,
args_string.c_str())) {
args_string)) {
if (m_command_options.m_help.OptionWasSet())
alias->SetHelp(m_command_options.m_help.GetCurrentValue());
if (m_command_options.m_long_help.OptionWasSet())
Expand Down Expand Up @@ -1713,7 +1713,7 @@ class CommandObjectCommandsScriptAdd : public CommandObjectParsed,
// everything should be fine now, let's add this alias

CommandObjectSP command_obj_sp(new CommandObjectPythonFunction(
m_interpreter, m_cmd_name, funct_name_str.c_str(), m_short_help,
m_interpreter, m_cmd_name, funct_name_str, m_short_help,
m_synchronicity));

if (!m_interpreter.AddUserCommand(m_cmd_name, command_obj_sp,
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Commands/CommandObjectFrame.cpp
Expand Up @@ -591,7 +591,7 @@ class CommandObjectFrameVariable : public CommandObjectParsed {
scope_string = GetScopeString(var_sp).str();

if (!scope_string.empty())
s.PutCString(scope_string.c_str());
s.PutCString(scope_string);

if (m_option_variable.show_decl &&
var_sp->GetDeclaration().GetFile()) {
Expand Down Expand Up @@ -637,7 +637,7 @@ class CommandObjectFrameVariable : public CommandObjectParsed {
scope_string = GetScopeString(var_sp).str();

if (!scope_string.empty())
s.PutCString(scope_string.c_str());
s.PutCString(scope_string);

// if (format != eFormatDefault)
// valobj_sp->SetFormat (format);
Expand Down Expand Up @@ -698,7 +698,7 @@ class CommandObjectFrameVariable : public CommandObjectParsed {
continue;

if (!scope_string.empty())
s.PutCString(scope_string.c_str());
s.PutCString(scope_string);

if (m_option_variable.show_decl &&
var_sp->GetDeclaration().GetFile()) {
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Commands/CommandObjectPlatform.cpp
Expand Up @@ -550,7 +550,7 @@ class CommandObjectPlatformFOpen : public CommandObjectParsed {
perms = lldb::eFilePermissionsUserRW | lldb::eFilePermissionsGroupRW |
lldb::eFilePermissionsWorldRead;
lldb::user_id_t fd = platform_sp->OpenFile(
FileSpec(cmd_line.c_str(), false),
FileSpec(cmd_line, false),
File::eOpenOptionRead | File::eOpenOptionWrite |
File::eOpenOptionAppend | File::eOpenOptionCanCreate,
perms, error);
Expand Down Expand Up @@ -957,7 +957,7 @@ class CommandObjectPlatformGetSize : public CommandObjectParsed {
if (platform_sp) {
std::string remote_file_path(args.GetArgumentAtIndex(0));
user_id_t size =
platform_sp->GetFileSize(FileSpec(remote_file_path.c_str(), false));
platform_sp->GetFileSize(FileSpec(remote_file_path, false));
if (size != UINT64_MAX) {
result.AppendMessageWithFormat("File size of %s (remote): %" PRIu64
"\n",
Expand Down Expand Up @@ -1793,7 +1793,7 @@ class CommandObjectPlatformShell : public CommandObjectRaw {
error = (platform_sp->RunShellCommand(expr, working_dir, &status, &signo,
&output, m_options.timeout));
if (!output.empty())
result.GetOutputStream().PutCString(output.c_str());
result.GetOutputStream().PutCString(output);
if (status > 0) {
if (signo > 0) {
const char *signo_cstr = Host::GetSignalAsCString(signo);
Expand Down
8 changes: 4 additions & 4 deletions lldb/source/Commands/CommandObjectSource.cpp
Expand Up @@ -609,7 +609,7 @@ class CommandObjectSourceInfo : public CommandObjectParsed {
m_module_list.Clear();
if (!m_options.modules.empty()) {
for (size_t i = 0, e = m_options.modules.size(); i < e; ++i) {
FileSpec module_file_spec(m_options.modules[i].c_str(), false);
FileSpec module_file_spec(m_options.modules[i], false);
if (module_file_spec) {
ModuleSpec module_spec(module_file_spec);
if (target->GetImages().FindModules(module_spec, m_module_list) == 0)
Expand Down Expand Up @@ -944,7 +944,7 @@ class CommandObjectSourceList : public CommandObjectParsed {
if (num_modules > 0) {
ModuleList matching_modules;
for (size_t i = 0; i < num_modules; ++i) {
FileSpec module_file_spec(m_options.modules[i].c_str(), false);
FileSpec module_file_spec(m_options.modules[i], false);
if (module_file_spec) {
ModuleSpec module_spec(module_file_spec);
matching_modules.Clear();
Expand All @@ -969,7 +969,7 @@ class CommandObjectSourceList : public CommandObjectParsed {
if (num_modules > 0) {
ModuleList matching_modules;
for (size_t i = 0; i < num_modules; ++i) {
FileSpec module_file_spec(m_options.modules[i].c_str(), false);
FileSpec module_file_spec(m_options.modules[i], false);
if (module_file_spec) {
ModuleSpec module_spec(module_file_spec);
matching_modules.Clear();
Expand Down Expand Up @@ -1228,7 +1228,7 @@ class CommandObjectSourceList : public CommandObjectParsed {
if (!m_options.modules.empty()) {
ModuleList matching_modules;
for (size_t i = 0, e = m_options.modules.size(); i < e; ++i) {
FileSpec module_file_spec(m_options.modules[i].c_str(), false);
FileSpec module_file_spec(m_options.modules[i], false);
if (module_file_spec) {
ModuleSpec module_spec(module_file_spec);
matching_modules.Clear();
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Commands/CommandObjectTarget.cpp
Expand Up @@ -1279,7 +1279,7 @@ static void DumpModuleArchitecture(Stream &strm, Module *module,
if (width)
strm.Printf("%-*s", width, arch_str.c_str());
else
strm.PutCString(arch_str.c_str());
strm.PutCString(arch_str);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Core/Broadcaster.cpp
Expand Up @@ -99,7 +99,7 @@ bool Broadcaster::BroadcasterImpl::GetEventNames(
s.PutCString(GetBroadcasterName());
s.PutChar('.');
}
s.PutCString(pos->second.c_str());
s.PutCString(pos->second);
++num_names_added;
}
}
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Core/Debugger.cpp
Expand Up @@ -280,7 +280,7 @@ Error Debugger::SetPropertyValue(const ExecutionContext *exe_ctx,
std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes(
new_prompt, GetUseColor());
if (str.length())
new_prompt = str.c_str();
new_prompt = str;
GetCommandInterpreter().UpdatePrompt(new_prompt);
EventSP prompt_change_event_sp(
new Event(CommandInterpreter::eBroadcastBitResetPrompt,
Expand Down Expand Up @@ -350,7 +350,7 @@ void Debugger::SetPrompt(llvm::StringRef p) {
std::string str =
lldb_utility::ansi::FormatAnsiTerminalCodes(new_prompt, GetUseColor());
if (str.length())
new_prompt = str.c_str();
new_prompt = str;
GetCommandInterpreter().UpdatePrompt(new_prompt);
}

Expand Down Expand Up @@ -1429,7 +1429,7 @@ void Debugger::HandleProcessEvent(const EventSP &event_sp) {
content_stream.Flush();

// Print it.
output_stream_sp->PutCString(content_stream.GetString().c_str());
output_stream_sp->PutCString(content_stream.GetString());
}
} else {
error_stream_sp->Printf("Failed to print structured "
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Core/Disassembler.cpp
Expand Up @@ -725,15 +725,15 @@ void Instruction::Dump(lldb_private::Stream *s, uint32_t max_opcode_byte_size,
opcode_column_width = m_opcode_name.length() + 1;
}

ss.PutCString(m_opcode_name.c_str());
ss.PutCString(m_opcode_name);
ss.FillLastLineToColumn(opcode_pos + opcode_column_width, ' ');
ss.PutCString(m_mnemonics.c_str());
ss.PutCString(m_mnemonics);

if (!m_comment.empty()) {
ss.FillLastLineToColumn(
opcode_pos + opcode_column_width + operand_column_width, ' ');
ss.PutCString(" ; ");
ss.PutCString(m_comment.c_str());
ss.PutCString(m_comment);
}
s->Write(ss.GetData(), ss.GetSize());
}
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Core/FormatEntity.cpp
Expand Up @@ -1106,7 +1106,7 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
return true; // Only return true if all items succeeded

case Entry::Type::String:
s.PutCString(entry.string.c_str());
s.PutCString(entry.string);
return true;

case Entry::Type::Scope: {
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Core/Log.cpp
Expand Up @@ -107,16 +107,16 @@ void Log::VAPrintf(const char *format, va_list args) {
llvm::raw_string_ostream stream(back_trace);
llvm::sys::PrintStackTrace(stream);
stream.flush();
header.PutCString(back_trace.c_str());
header.PutCString(back_trace);
}

if (m_options.Test(LLDB_LOG_OPTION_THREADSAFE)) {
static std::recursive_mutex g_LogThreadedMutex;
std::lock_guard<std::recursive_mutex> guard(g_LogThreadedMutex);
stream_sp->PutCString(header.GetString().c_str());
stream_sp->PutCString(header.GetString());
stream_sp->Flush();
} else {
stream_sp->PutCString(header.GetString().c_str());
stream_sp->PutCString(header.GetString());
stream_sp->Flush();
}
}
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Core/Module.cpp
Expand Up @@ -1208,7 +1208,7 @@ void Module::LogMessageVerboseBacktrace(Log *log, const char *format, ...) {
std::string back_trace;
llvm::raw_string_ostream stream(back_trace);
llvm::sys::PrintStackTrace(stream);
log_message.PutCString(back_trace.c_str());
log_message.PutCString(back_trace);
}
log->PutCString(log_message.GetString().c_str());
}
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Core/Scalar.cpp
Expand Up @@ -289,14 +289,14 @@ void Scalar::GetValue(Stream *s, bool show_type) const {
case e_slonglong:
case e_sint128:
case e_sint256:
s->PutCString(m_integer.toString(10, true).c_str());
s->PutCString(m_integer.toString(10, true));
break;
case e_uint:
case e_ulong:
case e_ulonglong:
case e_uint128:
case e_uint256:
s->PutCString(m_integer.toString(10, false).c_str());
s->PutCString(m_integer.toString(10, false));
break;
case e_float:
case e_double:
Expand Down
8 changes: 4 additions & 4 deletions lldb/source/Core/SearchFilter.cpp
Expand Up @@ -477,7 +477,7 @@ SearchFilterSP SearchFilterByModule::CreateFromStructuredData(
error.SetErrorString("SFBM::CFSD: filter module item not a string.");
return nullptr;
}
FileSpec module_spec(module.c_str(), false);
FileSpec module_spec(module, false);

return SearchFilterSP(
new SearchFilterByModule(target.shared_from_this(), module_spec));
Expand Down Expand Up @@ -646,7 +646,7 @@ SearchFilterSP SearchFilterByModuleList::CreateFromStructuredData(
"SFBM::CFSD: filter module item %zu not a string.", i);
return nullptr;
}
modules.Append(FileSpec(module.c_str(), false));
modules.Append(FileSpec(module, false));
}
}

Expand Down Expand Up @@ -711,7 +711,7 @@ lldb::SearchFilterSP SearchFilterByModuleListAndCU::CreateFromStructuredData(
"SFBM::CFSD: filter module item %zu not a string.", i);
return result_sp;
}
modules.Append(FileSpec(module.c_str(), false));
modules.Append(FileSpec(module, false));
}
}

Expand All @@ -733,7 +733,7 @@ lldb::SearchFilterSP SearchFilterByModuleListAndCU::CreateFromStructuredData(
"SFBM::CFSD: filter cu item %zu not a string.", i);
return nullptr;
}
cus.Append(FileSpec(cu.c_str(), false));
cus.Append(FileSpec(cu, false));
}

return SearchFilterSP(new SearchFilterByModuleListAndCU(
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Core/StructuredData.cpp
Expand Up @@ -181,7 +181,7 @@ StructuredData::Object::GetObjectForDotSeparatedPath(llvm::StringRef path) {
if (this->GetType() == Type::eTypeDictionary) {
std::pair<llvm::StringRef, llvm::StringRef> match = path.split('.');
std::string key = match.first.str();
ObjectSP value = this->GetAsDictionary()->GetValueForKey(key.c_str());
ObjectSP value = this->GetAsDictionary()->GetValueForKey(key);
if (value.get()) {
// Do we have additional words to descend? If not, return the
// value we're at right now.
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Core/ValueObject.cpp
Expand Up @@ -2034,7 +2034,7 @@ bool ValueObject::GetBaseClassPath(Stream &s) {
if (this_had_base_class) {
if (parent_had_base_class)
s.PutCString("::");
s.PutCString(cxx_class_name.c_str());
s.PutCString(cxx_class_name);
}
return parent_had_base_class || this_had_base_class;
}
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/DataFormatters/TypeSummary.cpp
Expand Up @@ -207,10 +207,10 @@ std::string ScriptSummaryFormat::GetDescription() {
if (m_function_name.empty()) {
sstr.PutCString("no backing script");
} else {
sstr.PutCString(m_function_name.c_str());
sstr.PutCString(m_function_name);
}
} else {
sstr.PutCString(m_python_script.c_str());
sstr.PutCString(m_python_script);
}
return sstr.GetString();
}
2 changes: 1 addition & 1 deletion lldb/source/Expression/IRDynamicChecks.cpp
Expand Up @@ -562,7 +562,7 @@ IRDynamicChecks::~IRDynamicChecks() = default;
bool IRDynamicChecks::runOnModule(llvm::Module &M) {
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));

llvm::Function *function = M.getFunction(StringRef(m_func_name.c_str()));
llvm::Function *function = M.getFunction(StringRef(m_func_name));

if (!function) {
if (log)
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Expression/REPL.cpp
Expand Up @@ -433,7 +433,7 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) {

// Now set the default file and line to the REPL source file
m_target.GetSourceManager().SetDefaultFileAndLine(
FileSpec(m_repl_source_path.c_str(), false), new_default_line);
FileSpec(m_repl_source_path, false), new_default_line);
}
static_cast<IOHandlerEditline &>(io_handler)
.SetBaseLineNumber(m_code.GetSize() + 1);
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Host/common/FileSpec.cpp
Expand Up @@ -610,7 +610,7 @@ FileSpec FileSpec::GetNormalizedPath() const {
void FileSpec::Dump(Stream *s) const {
if (s) {
std::string path{GetPath(true)};
s->PutCString(path.c_str());
s->PutCString(path);
char path_separator = GetPreferredPathSeparator(m_syntax);
if (!m_filename && !path.empty() && path.back() != path_separator)
s->PutChar(path_separator);
Expand Down

0 comments on commit 771ef6d

Please sign in to comment.