Skip to content

[NFC][sanitizer] Rename InternalScopedString::append to AppendF #66558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 34 additions & 34 deletions compiler-rt/lib/asan/asan_descriptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ void DescribeThread(AsanThreadContext *context) {
}
context->announced = true;
InternalScopedString str;
str.append("Thread %s", AsanThreadIdAndName(context).c_str());
str.AppendF("Thread %s", AsanThreadIdAndName(context).c_str());
if (context->parent_tid == kInvalidTid) {
str.append(" created by unknown thread\n");
str.AppendF(" created by unknown thread\n");
Printf("%s", str.data());
return;
}
str.append(" created by %s here:\n",
AsanThreadIdAndName(context->parent_tid).c_str());
str.AppendF(" created by %s here:\n",
AsanThreadIdAndName(context->parent_tid).c_str());
Printf("%s", str.data());
StackDepotGet(context->stack_id).Print();
// Recursively described parent thread if needed.
Expand Down Expand Up @@ -126,29 +126,29 @@ static void GetAccessToHeapChunkInformation(ChunkAccess *descr,
static void PrintHeapChunkAccess(uptr addr, const ChunkAccess &descr) {
Decorator d;
InternalScopedString str;
str.append("%s", d.Location());
str.AppendF("%s", d.Location());
switch (descr.access_type) {
case kAccessTypeLeft:
str.append("%p is located %zd bytes before",
(void *)descr.bad_addr, descr.offset);
str.AppendF("%p is located %zd bytes before", (void *)descr.bad_addr,
descr.offset);
break;
case kAccessTypeRight:
str.append("%p is located %zd bytes after",
(void *)descr.bad_addr, descr.offset);
str.AppendF("%p is located %zd bytes after", (void *)descr.bad_addr,
descr.offset);
break;
case kAccessTypeInside:
str.append("%p is located %zd bytes inside of", (void *)descr.bad_addr,
descr.offset);
str.AppendF("%p is located %zd bytes inside of", (void *)descr.bad_addr,
descr.offset);
break;
case kAccessTypeUnknown:
str.append(
str.AppendF(
"%p is located somewhere around (this is AddressSanitizer bug!)",
(void *)descr.bad_addr);
}
str.append(" %zu-byte region [%p,%p)\n", descr.chunk_size,
(void *)descr.chunk_begin,
(void *)(descr.chunk_begin + descr.chunk_size));
str.append("%s", d.Default());
str.AppendF(" %zu-byte region [%p,%p)\n", descr.chunk_size,
(void *)descr.chunk_begin,
(void *)(descr.chunk_begin + descr.chunk_size));
str.AppendF("%s", d.Default());
Printf("%s", str.data());
}

Expand Down Expand Up @@ -243,24 +243,24 @@ static void PrintAccessAndVarIntersection(const StackVarDescr &var, uptr addr,
pos_descr = "underflows";
}
InternalScopedString str;
str.append(" [%zd, %zd)", var.beg, var_end);
str.AppendF(" [%zd, %zd)", var.beg, var_end);
// Render variable name.
str.append(" '");
str.AppendF(" '");
for (uptr i = 0; i < var.name_len; ++i) {
str.append("%c", var.name_pos[i]);
str.AppendF("%c", var.name_pos[i]);
}
str.append("'");
str.AppendF("'");
if (var.line > 0) {
str.append(" (line %zd)", var.line);
str.AppendF(" (line %zd)", var.line);
}
if (pos_descr) {
Decorator d;
// FIXME: we may want to also print the size of the access here,
// but in case of accesses generated by memset it may be confusing.
str.append("%s <== Memory access at offset %zd %s this variable%s\n",
d.Location(), addr, pos_descr, d.Default());
str.AppendF("%s <== Memory access at offset %zd %s this variable%s\n",
d.Location(), addr, pos_descr, d.Default());
} else {
str.append("\n");
str.AppendF("\n");
}
Printf("%s", str.data());
}
Expand All @@ -277,23 +277,23 @@ static void DescribeAddressRelativeToGlobal(uptr addr, uptr access_size,
const __asan_global &g) {
InternalScopedString str;
Decorator d;
str.append("%s", d.Location());
str.AppendF("%s", d.Location());
if (addr < g.beg) {
str.append("%p is located %zd bytes before", (void *)addr,
g.beg - addr);
str.AppendF("%p is located %zd bytes before", (void *)addr, g.beg - addr);
} else if (addr + access_size > g.beg + g.size) {
if (addr < g.beg + g.size) addr = g.beg + g.size;
str.append("%p is located %zd bytes after", (void *)addr,
addr - (g.beg + g.size));
str.AppendF("%p is located %zd bytes after", (void *)addr,
addr - (g.beg + g.size));
} else {
// Can it happen?
str.append("%p is located %zd bytes inside of", (void *)addr, addr - g.beg);
str.AppendF("%p is located %zd bytes inside of", (void *)addr,
addr - g.beg);
}
str.append(" global variable '%s' defined in '",
MaybeDemangleGlobalName(g.name));
str.AppendF(" global variable '%s' defined in '",
MaybeDemangleGlobalName(g.name));
PrintGlobalLocation(&str, g);
str.append("' (0x%zx) of size %zu\n", g.beg, g.size);
str.append("%s", d.Default());
str.AppendF("' (0x%zx) of size %zu\n", g.beg, g.size);
str.AppendF("%s", d.Default());
PrintGlobalNameIfASCII(&str, g);
Printf("%s", str.data());
}
Expand Down
18 changes: 9 additions & 9 deletions compiler-rt/lib/asan/asan_errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ void ErrorODRViolation::Print() {
"HINT: if you don't care about these errors you may set "
"ASAN_OPTIONS=detect_odr_violation=0\n");
InternalScopedString error_msg;
error_msg.append("%s: global '%s' at %s", scariness.GetDescription(),
MaybeDemangleGlobalName(global1.name), g1_loc.data());
error_msg.AppendF("%s: global '%s' at %s", scariness.GetDescription(),
MaybeDemangleGlobalName(global1.name), g1_loc.data());
ReportErrorSummary(error_msg.data());
}

Expand Down Expand Up @@ -517,15 +517,15 @@ static void PrintShadowByte(InternalScopedString *str, const char *before,
}

static void PrintLegend(InternalScopedString *str) {
str->append(
str->AppendF(
"Shadow byte legend (one shadow byte represents %d "
"application bytes):\n",
(int)ASAN_SHADOW_GRANULARITY);
PrintShadowByte(str, " Addressable: ", 0);
str->append(" Partially addressable: ");
str->AppendF(" Partially addressable: ");
for (u8 i = 1; i < ASAN_SHADOW_GRANULARITY; i++)
PrintShadowByte(str, "", i, " ");
str->append("\n");
str->AppendF("\n");
PrintShadowByte(str, " Heap left redzone: ",
kAsanHeapLeftRedzoneMagic);
PrintShadowByte(str, " Freed heap region: ", kAsanHeapFreeMagic);
Expand Down Expand Up @@ -559,16 +559,16 @@ static void PrintShadowBytes(InternalScopedString *str, const char *before,
u8 *bytes, u8 *guilty, uptr n) {
Decorator d;
if (before)
str->append("%s%p:", before,
(void *)ShadowToMem(reinterpret_cast<uptr>(bytes)));
str->AppendF("%s%p:", before,
(void *)ShadowToMem(reinterpret_cast<uptr>(bytes)));
for (uptr i = 0; i < n; i++) {
u8 *p = bytes + i;
const char *before =
p == guilty ? "[" : (p - 1 == guilty && i != 0) ? "" : " ";
const char *after = p == guilty ? "]" : "";
PrintShadowByte(str, before, *p, after);
}
str->append("\n");
str->AppendF("\n");
}

static void PrintShadowMemoryForAddress(uptr addr) {
Expand All @@ -577,7 +577,7 @@ static void PrintShadowMemoryForAddress(uptr addr) {
const uptr n_bytes_per_row = 16;
uptr aligned_shadow = shadow_addr & ~(n_bytes_per_row - 1);
InternalScopedString str;
str.append("Shadow bytes around the buggy address:\n");
str.AppendF("Shadow bytes around the buggy address:\n");
for (int i = -5; i <= 5; i++) {
uptr row_shadow_addr = aligned_shadow + i * n_bytes_per_row;
// Skip rows that would be outside the shadow range. This can happen when
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/asan/asan_fake_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ void FakeStack::Destroy(int tid) {
if (Verbosity() >= 2) {
InternalScopedString str;
for (uptr class_id = 0; class_id < kNumberOfSizeClasses; class_id++)
str.append("%zd: %zd/%zd; ", class_id, hint_position_[class_id],
NumberOfFrames(stack_size_log(), class_id));
str.AppendF("%zd: %zd/%zd; ", class_id, hint_position_[class_id],
NumberOfFrames(stack_size_log(), class_id));
Report("T%d: FakeStack destroyed: %s\n", tid, str.data());
}
uptr size = RequiredSize(stack_size_log_);
Expand Down
17 changes: 10 additions & 7 deletions compiler-rt/lib/asan/asan_globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,23 +295,26 @@ void PrintGlobalNameIfASCII(InternalScopedString *str, const __asan_global &g) {
if (c == '\0' || !IsASCII(c)) return;
}
if (*(char *)(g.beg + g.size - 1) != '\0') return;
str->append(" '%s' is ascii string '%s'\n", MaybeDemangleGlobalName(g.name),
(char *)g.beg);
str->AppendF(" '%s' is ascii string '%s'\n", MaybeDemangleGlobalName(g.name),
(char *)g.beg);
}

void PrintGlobalLocation(InternalScopedString *str, const __asan_global &g) {
DataInfo info;
Symbolizer::GetOrInit()->SymbolizeData(g.beg, &info);

if (info.line != 0) {
str->append("%s:%d", info.file, static_cast<int>(info.line));
str->AppendF("%s:%d", info.file, static_cast<int>(info.line));
} else if (g.gcc_location != 0) {
// Fallback to Global::gcc_location
str->append("%s", g.gcc_location->filename ? g.gcc_location->filename : g.module_name);
if (g.gcc_location->line_no) str->append(":%d", g.gcc_location->line_no);
if (g.gcc_location->column_no) str->append(":%d", g.gcc_location->column_no);
str->AppendF("%s", g.gcc_location->filename ? g.gcc_location->filename
: g.module_name);
if (g.gcc_location->line_no)
str->AppendF(":%d", g.gcc_location->line_no);
if (g.gcc_location->column_no)
str->AppendF(":%d", g.gcc_location->column_no);
} else {
str->append("%s", g.module_name);
str->AppendF("%s", g.module_name);
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler-rt/lib/asan/asan_report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ void AppendToErrorMessageBuffer(const char *buffer) {
void PrintMemoryByte(InternalScopedString *str, const char *before, u8 byte,
bool in_shadow, const char *after) {
Decorator d;
str->append("%s%s%x%x%s%s", before,
in_shadow ? d.ShadowByte(byte) : d.MemoryByte(), byte >> 4,
byte & 15, d.Default(), after);
str->AppendF("%s%s%x%x%s%s", before,
in_shadow ? d.ShadowByte(byte) : d.MemoryByte(), byte >> 4,
byte & 15, d.Default(), after);
}

static void PrintZoneForPointer(uptr ptr, uptr zone_ptr,
Expand Down
12 changes: 6 additions & 6 deletions compiler-rt/lib/dfsan/dfsan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,12 +823,12 @@ bool PrintOriginTraceFramesToStr(Origin o, InternalScopedString *out) {
dfsan_origin origin_id = o.raw_id();
o = o.getNextChainedOrigin(&stack);
if (o.isChainedOrigin())
out->append(
out->AppendF(
" %sOrigin value: 0x%x, Taint value was stored to memory at%s\n",
d.Origin(), origin_id, d.Default());
else
out->append(" %sOrigin value: 0x%x, Taint value was created at%s\n",
d.Origin(), origin_id, d.Default());
out->AppendF(" %sOrigin value: 0x%x, Taint value was created at%s\n",
d.Origin(), origin_id, d.Default());

// Includes a trailing newline, so no need to add it again.
stack.PrintTo(out);
Expand All @@ -849,9 +849,9 @@ bool PrintOriginTraceToStr(const void *addr, const char *description,

const dfsan_origin origin = *__dfsan::origin_for(addr);

out->append(" %sTaint value 0x%x (at %p) origin tracking (%s)%s\n",
d.Origin(), label, addr, description ? description : "",
d.Default());
out->AppendF(" %sTaint value 0x%x (at %p) origin tracking (%s)%s\n",
d.Origin(), label, addr, description ? description : "",
d.Default());

Origin o = Origin::FromRawId(origin);
return PrintOriginTraceFramesToStr(o, out);
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/hwasan/hwasan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ static void HwasanFormatMemoryUsage(InternalScopedString &s) {
auto sds = StackDepotGetStats();
AllocatorStatCounters asc;
GetAllocatorStats(asc);
s.append(
s.AppendF(
"HWASAN pid: %d rss: %zd threads: %zd stacks: %zd"
" thr_aux: %zd stack_depot: %zd uniq_stacks: %zd"
" heap: %zd",
Expand Down
68 changes: 33 additions & 35 deletions compiler-rt/lib/hwasan/hwasan_report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ static void PrintStackAllocations(StackAllocationsRingBuffer *sa,
break;
uptr pc_mask = (1ULL << 48) - 1;
uptr pc = record & pc_mask;
frame_desc.append(" record_addr:0x%zx record:0x%zx",
reinterpret_cast<uptr>(record_addr), record);
frame_desc.AppendF(" record_addr:0x%zx record:0x%zx",
reinterpret_cast<uptr>(record_addr), record);
if (SymbolizedStack *frame = Symbolizer::GetOrInit()->SymbolizePC(pc)) {
RenderFrame(&frame_desc, " %F %L", 0, frame->info.address, &frame->info,
common_flags()->symbolize_vs_style,
Expand Down Expand Up @@ -528,14 +528,14 @@ static void PrintTagInfoAroundAddr(tag_t *tag_ptr, uptr num_rows,
tag_t *end_row = center_row_beg + row_len * ((num_rows + 1) / 2);
InternalScopedString s;
for (tag_t *row = beg_row; row < end_row; row += row_len) {
s.append("%s", row == center_row_beg ? "=>" : " ");
s.append("%p:", (void *)ShadowToMem(reinterpret_cast<uptr>(row)));
s.AppendF("%s", row == center_row_beg ? "=>" : " ");
s.AppendF("%p:", (void *)ShadowToMem(reinterpret_cast<uptr>(row)));
for (uptr i = 0; i < row_len; i++) {
s.append("%s", row + i == tag_ptr ? "[" : " ");
s.AppendF("%s", row + i == tag_ptr ? "[" : " ");
print_tag(s, &row[i]);
s.append("%s", row + i == tag_ptr ? "]" : " ");
s.AppendF("%s", row + i == tag_ptr ? "]" : " ");
}
s.append("\n");
s.AppendF("\n");
}
Printf("%s", s.data());
}
Expand All @@ -545,7 +545,7 @@ static void PrintTagsAroundAddr(tag_t *tag_ptr) {
"Memory tags around the buggy address (one tag corresponds to %zd "
"bytes):\n", kShadowAlignment);
PrintTagInfoAroundAddr(tag_ptr, 17, [](InternalScopedString &s, tag_t *tag) {
s.append("%02x", *tag);
s.AppendF("%02x", *tag);
});

Printf(
Expand All @@ -555,10 +555,10 @@ static void PrintTagsAroundAddr(tag_t *tag_ptr) {
PrintTagInfoAroundAddr(tag_ptr, 3, [](InternalScopedString &s, tag_t *tag) {
if (*tag >= 1 && *tag <= kShadowAlignment) {
uptr granule_addr = ShadowToMem(reinterpret_cast<uptr>(tag));
s.append("%02x",
*reinterpret_cast<u8 *>(granule_addr + kShadowAlignment - 1));
s.AppendF("%02x",
*reinterpret_cast<u8 *>(granule_addr + kShadowAlignment - 1));
} else {
s.append("..");
s.AppendF("..");
}
});
Printf(
Expand Down Expand Up @@ -654,31 +654,29 @@ void ReportTailOverwritten(StackTrace *stack, uptr tagged_addr, uptr orig_size,
CHECK_GT(tail_size, 0U);
CHECK_LT(tail_size, kShadowAlignment);
u8 *tail = reinterpret_cast<u8*>(untagged_addr + orig_size);
s.append("Tail contains: ");
for (uptr i = 0; i < kShadowAlignment - tail_size; i++)
s.append(".. ");
s.AppendF("Tail contains: ");
for (uptr i = 0; i < kShadowAlignment - tail_size; i++) s.AppendF(".. ");
for (uptr i = 0; i < tail_size; i++) s.AppendF("%02x ", tail[i]);
s.AppendF("\n");
s.AppendF("Expected: ");
for (uptr i = 0; i < kShadowAlignment - tail_size; i++) s.AppendF(".. ");
for (uptr i = 0; i < tail_size; i++) s.AppendF("%02x ", actual_expected[i]);
s.AppendF("\n");
s.AppendF(" ");
for (uptr i = 0; i < kShadowAlignment - tail_size; i++) s.AppendF(" ");
for (uptr i = 0; i < tail_size; i++)
s.append("%02x ", tail[i]);
s.append("\n");
s.append("Expected: ");
for (uptr i = 0; i < kShadowAlignment - tail_size; i++)
s.append(".. ");
for (uptr i = 0; i < tail_size; i++) s.append("%02x ", actual_expected[i]);
s.append("\n");
s.append(" ");
for (uptr i = 0; i < kShadowAlignment - tail_size; i++)
s.append(" ");
for (uptr i = 0; i < tail_size; i++)
s.append("%s ", actual_expected[i] != tail[i] ? "^^" : " ");

s.append("\nThis error occurs when a buffer overflow overwrites memory\n"
"after a heap object, but within the %zd-byte granule, e.g.\n"
" char *x = new char[20];\n"
" x[25] = 42;\n"
"%s does not detect such bugs in uninstrumented code at the time of write,"
"\nbut can detect them at the time of free/delete.\n"
"To disable this feature set HWASAN_OPTIONS=free_checks_tail_magic=0\n",
kShadowAlignment, SanitizerToolName);
s.AppendF("%s ", actual_expected[i] != tail[i] ? "^^" : " ");

s.AppendF(
"\nThis error occurs when a buffer overflow overwrites memory\n"
"after a heap object, but within the %zd-byte granule, e.g.\n"
" char *x = new char[20];\n"
" x[25] = 42;\n"
"%s does not detect such bugs in uninstrumented code at the time of "
"write,"
"\nbut can detect them at the time of free/delete.\n"
"To disable this feature set HWASAN_OPTIONS=free_checks_tail_magic=0\n",
kShadowAlignment, SanitizerToolName);
Printf("%s", s.data());
GetCurrentThread()->Announce();

Expand Down
Loading