diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp --- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp @@ -39,9 +39,9 @@ } const char *ExtractInt(const char *str, const char *delims, int *result) { - char *buff; + char *buff = nullptr; const char *ret = ExtractToken(str, delims, &buff); - if (buff != 0) { + if (buff) { *result = (int)internal_atoll(buff); } InternalFree(buff); @@ -49,9 +49,9 @@ } const char *ExtractUptr(const char *str, const char *delims, uptr *result) { - char *buff; + char *buff = nullptr; const char *ret = ExtractToken(str, delims, &buff); - if (buff != 0) { + if (buff) { *result = (uptr)internal_atoll(buff); } InternalFree(buff); @@ -59,9 +59,9 @@ } const char *ExtractSptr(const char *str, const char *delims, sptr *result) { - char *buff; + char *buff = nullptr; const char *ret = ExtractToken(str, delims, &buff); - if (buff != 0) { + if (buff) { *result = (sptr)internal_atoll(buff); } InternalFree(buff); @@ -83,7 +83,7 @@ SymbolizedStack *Symbolizer::SymbolizePC(uptr addr) { BlockingMutexLock l(&mu_); - const char *module_name; + const char *module_name = nullptr; uptr module_offset; ModuleArch arch; SymbolizedStack *res = SymbolizedStack::New(addr); @@ -103,7 +103,7 @@ bool Symbolizer::SymbolizeData(uptr addr, DataInfo *info) { BlockingMutexLock l(&mu_); - const char *module_name; + const char *module_name = nullptr; uptr module_offset; ModuleArch arch; if (!FindModuleNameAndOffsetForAddress(addr, &module_name, &module_offset, @@ -124,7 +124,7 @@ bool Symbolizer::SymbolizeFrame(uptr addr, FrameInfo *info) { BlockingMutexLock l(&mu_); - const char *module_name; + const char *module_name = nullptr; if (!FindModuleNameAndOffsetForAddress( addr, &module_name, &info->module_offset, &info->module_arch)) return false; @@ -175,7 +175,7 @@ uptr *module_offset, ModuleArch *module_arch) { const LoadedModule *module = FindModuleForAddress(address); - if (module == nullptr) + if (!module) return false; *module_name = module->full_name(); *module_offset = address - module->base_address(); @@ -292,7 +292,7 @@ // Windows, so extract tokens from the right hand side first. The column info is // also optional. static const char *ParseFileLineInfo(AddressInfo *info, const char *str) { - char *file_line_info = 0; + char *file_line_info = nullptr; str = ExtractToken(str, "\n", &file_line_info); CHECK(file_line_info); @@ -323,7 +323,7 @@ bool top_frame = true; SymbolizedStack *last = res; while (true) { - char *function_name = 0; + char *function_name = nullptr; str = ExtractToken(str, "\n", &function_name); CHECK(function_name); if (function_name[0] == '\0') { @@ -402,32 +402,29 @@ AddressInfo *info = &stack->info; const char *buf = FormatAndSendCommand( "CODE", info->module, info->module_offset, info->module_arch); - if (buf) { - ParseSymbolizePCOutput(buf, stack); - return true; - } - return false; + if (!buf) + return false; + ParseSymbolizePCOutput(buf, stack); + return true; } bool LLVMSymbolizer::SymbolizeData(uptr addr, DataInfo *info) { const char *buf = FormatAndSendCommand( "DATA", info->module, info->module_offset, info->module_arch); - if (buf) { - ParseSymbolizeDataOutput(buf, info); - info->start += (addr - info->module_offset); // Add the base address. - return true; - } - return false; + if (!buf) + return false; + ParseSymbolizeDataOutput(buf, info); + info->start += (addr - info->module_offset); // Add the base address. + return true; } bool LLVMSymbolizer::SymbolizeFrame(uptr addr, FrameInfo *info) { const char *buf = FormatAndSendCommand( "FRAME", info->module, info->module_offset, info->module_arch); - if (buf) { - ParseSymbolizeFrameOutput(buf, &info->locals); - return true; - } - return false; + if (!buf) + return false; + ParseSymbolizeFrameOutput(buf, &info->locals); + return true; } const char *LLVMSymbolizer::FormatAndSendCommand(const char *command_prefix, @@ -435,21 +432,21 @@ uptr module_offset, ModuleArch arch) { CHECK(module_name); - if (arch == kModuleArchUnknown) { - if (internal_snprintf(buffer_, kBufferSize, "%s \"%s\" 0x%zx\n", - command_prefix, module_name, - module_offset) >= static_cast(kBufferSize)) { - Report("WARNING: Command buffer too small"); - return nullptr; - } - } else { - if (internal_snprintf(buffer_, kBufferSize, "%s \"%s:%s\" 0x%zx\n", - command_prefix, module_name, ModuleArchToString(arch), - module_offset) >= static_cast(kBufferSize)) { - Report("WARNING: Command buffer too small"); - return nullptr; - } + int size_needed = 0; + if (arch == kModuleArchUnknown) + size_needed = internal_snprintf(buffer_, kBufferSize, "%s \"%s\" 0x%zx\n", + command_prefix, module_name, module_offset); + else + size_needed = internal_snprintf(buffer_, kBufferSize, + "%s \"%s:%s\" 0x%zx\n", command_prefix, + module_name, ModuleArchToString(arch), + module_offset); + + if (size_needed >= static_cast(kBufferSize)) { + Report("WARNING: Command buffer too small"); + return nullptr; } + return symbolizer_process_->SendCommand(buffer_); } @@ -492,16 +489,16 @@ Report("WARNING: Failed to use and restart external symbolizer!\n"); failed_to_start_ = true; } - return 0; + return nullptr; } const char *SymbolizerProcess::SendCommandImpl(const char *command) { if (input_fd_ == kInvalidFd || output_fd_ == kInvalidFd) - return 0; + return nullptr; if (!WriteToSymbolizer(command, internal_strlen(command))) - return 0; + return nullptr; if (!ReadFromSymbolizer(buffer_, kBufferSize)) - return 0; + return nullptr; return buffer_; } @@ -532,8 +529,8 @@ break; if (read_len + 1 == max_length) { Report("WARNING: Symbolizer buffer too small\n"); - read_len = 0; - break; + buffer[0] = '\0'; + return false; } } buffer[read_len] = '\0';