Skip to content

Commit 5b7dfa9

Browse files
authored
[NFC][sanitizer] Rename InternalScopedString::append to AppendF (#66558)
Prepare to introduce trivial InternalScopedString::Append(const char*).
1 parent c663401 commit 5b7dfa9

26 files changed

+206
-204
lines changed

compiler-rt/lib/asan/asan_descriptions.cpp

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ void DescribeThread(AsanThreadContext *context) {
4949
}
5050
context->announced = true;
5151
InternalScopedString str;
52-
str.append("Thread %s", AsanThreadIdAndName(context).c_str());
52+
str.AppendF("Thread %s", AsanThreadIdAndName(context).c_str());
5353
if (context->parent_tid == kInvalidTid) {
54-
str.append(" created by unknown thread\n");
54+
str.AppendF(" created by unknown thread\n");
5555
Printf("%s", str.data());
5656
return;
5757
}
58-
str.append(" created by %s here:\n",
59-
AsanThreadIdAndName(context->parent_tid).c_str());
58+
str.AppendF(" created by %s here:\n",
59+
AsanThreadIdAndName(context->parent_tid).c_str());
6060
Printf("%s", str.data());
6161
StackDepotGet(context->stack_id).Print();
6262
// Recursively described parent thread if needed.
@@ -126,29 +126,29 @@ static void GetAccessToHeapChunkInformation(ChunkAccess *descr,
126126
static void PrintHeapChunkAccess(uptr addr, const ChunkAccess &descr) {
127127
Decorator d;
128128
InternalScopedString str;
129-
str.append("%s", d.Location());
129+
str.AppendF("%s", d.Location());
130130
switch (descr.access_type) {
131131
case kAccessTypeLeft:
132-
str.append("%p is located %zd bytes before",
133-
(void *)descr.bad_addr, descr.offset);
132+
str.AppendF("%p is located %zd bytes before", (void *)descr.bad_addr,
133+
descr.offset);
134134
break;
135135
case kAccessTypeRight:
136-
str.append("%p is located %zd bytes after",
137-
(void *)descr.bad_addr, descr.offset);
136+
str.AppendF("%p is located %zd bytes after", (void *)descr.bad_addr,
137+
descr.offset);
138138
break;
139139
case kAccessTypeInside:
140-
str.append("%p is located %zd bytes inside of", (void *)descr.bad_addr,
141-
descr.offset);
140+
str.AppendF("%p is located %zd bytes inside of", (void *)descr.bad_addr,
141+
descr.offset);
142142
break;
143143
case kAccessTypeUnknown:
144-
str.append(
144+
str.AppendF(
145145
"%p is located somewhere around (this is AddressSanitizer bug!)",
146146
(void *)descr.bad_addr);
147147
}
148-
str.append(" %zu-byte region [%p,%p)\n", descr.chunk_size,
149-
(void *)descr.chunk_begin,
150-
(void *)(descr.chunk_begin + descr.chunk_size));
151-
str.append("%s", d.Default());
148+
str.AppendF(" %zu-byte region [%p,%p)\n", descr.chunk_size,
149+
(void *)descr.chunk_begin,
150+
(void *)(descr.chunk_begin + descr.chunk_size));
151+
str.AppendF("%s", d.Default());
152152
Printf("%s", str.data());
153153
}
154154

@@ -243,24 +243,24 @@ static void PrintAccessAndVarIntersection(const StackVarDescr &var, uptr addr,
243243
pos_descr = "underflows";
244244
}
245245
InternalScopedString str;
246-
str.append(" [%zd, %zd)", var.beg, var_end);
246+
str.AppendF(" [%zd, %zd)", var.beg, var_end);
247247
// Render variable name.
248-
str.append(" '");
248+
str.AppendF(" '");
249249
for (uptr i = 0; i < var.name_len; ++i) {
250-
str.append("%c", var.name_pos[i]);
250+
str.AppendF("%c", var.name_pos[i]);
251251
}
252-
str.append("'");
252+
str.AppendF("'");
253253
if (var.line > 0) {
254-
str.append(" (line %zd)", var.line);
254+
str.AppendF(" (line %zd)", var.line);
255255
}
256256
if (pos_descr) {
257257
Decorator d;
258258
// FIXME: we may want to also print the size of the access here,
259259
// but in case of accesses generated by memset it may be confusing.
260-
str.append("%s <== Memory access at offset %zd %s this variable%s\n",
261-
d.Location(), addr, pos_descr, d.Default());
260+
str.AppendF("%s <== Memory access at offset %zd %s this variable%s\n",
261+
d.Location(), addr, pos_descr, d.Default());
262262
} else {
263-
str.append("\n");
263+
str.AppendF("\n");
264264
}
265265
Printf("%s", str.data());
266266
}
@@ -277,23 +277,23 @@ static void DescribeAddressRelativeToGlobal(uptr addr, uptr access_size,
277277
const __asan_global &g) {
278278
InternalScopedString str;
279279
Decorator d;
280-
str.append("%s", d.Location());
280+
str.AppendF("%s", d.Location());
281281
if (addr < g.beg) {
282-
str.append("%p is located %zd bytes before", (void *)addr,
283-
g.beg - addr);
282+
str.AppendF("%p is located %zd bytes before", (void *)addr, g.beg - addr);
284283
} else if (addr + access_size > g.beg + g.size) {
285284
if (addr < g.beg + g.size) addr = g.beg + g.size;
286-
str.append("%p is located %zd bytes after", (void *)addr,
287-
addr - (g.beg + g.size));
285+
str.AppendF("%p is located %zd bytes after", (void *)addr,
286+
addr - (g.beg + g.size));
288287
} else {
289288
// Can it happen?
290-
str.append("%p is located %zd bytes inside of", (void *)addr, addr - g.beg);
289+
str.AppendF("%p is located %zd bytes inside of", (void *)addr,
290+
addr - g.beg);
291291
}
292-
str.append(" global variable '%s' defined in '",
293-
MaybeDemangleGlobalName(g.name));
292+
str.AppendF(" global variable '%s' defined in '",
293+
MaybeDemangleGlobalName(g.name));
294294
PrintGlobalLocation(&str, g);
295-
str.append("' (0x%zx) of size %zu\n", g.beg, g.size);
296-
str.append("%s", d.Default());
295+
str.AppendF("' (0x%zx) of size %zu\n", g.beg, g.size);
296+
str.AppendF("%s", d.Default());
297297
PrintGlobalNameIfASCII(&str, g);
298298
Printf("%s", str.data());
299299
}

compiler-rt/lib/asan/asan_errors.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ void ErrorODRViolation::Print() {
379379
"HINT: if you don't care about these errors you may set "
380380
"ASAN_OPTIONS=detect_odr_violation=0\n");
381381
InternalScopedString error_msg;
382-
error_msg.append("%s: global '%s' at %s", scariness.GetDescription(),
383-
MaybeDemangleGlobalName(global1.name), g1_loc.data());
382+
error_msg.AppendF("%s: global '%s' at %s", scariness.GetDescription(),
383+
MaybeDemangleGlobalName(global1.name), g1_loc.data());
384384
ReportErrorSummary(error_msg.data());
385385
}
386386

@@ -517,15 +517,15 @@ static void PrintShadowByte(InternalScopedString *str, const char *before,
517517
}
518518

519519
static void PrintLegend(InternalScopedString *str) {
520-
str->append(
520+
str->AppendF(
521521
"Shadow byte legend (one shadow byte represents %d "
522522
"application bytes):\n",
523523
(int)ASAN_SHADOW_GRANULARITY);
524524
PrintShadowByte(str, " Addressable: ", 0);
525-
str->append(" Partially addressable: ");
525+
str->AppendF(" Partially addressable: ");
526526
for (u8 i = 1; i < ASAN_SHADOW_GRANULARITY; i++)
527527
PrintShadowByte(str, "", i, " ");
528-
str->append("\n");
528+
str->AppendF("\n");
529529
PrintShadowByte(str, " Heap left redzone: ",
530530
kAsanHeapLeftRedzoneMagic);
531531
PrintShadowByte(str, " Freed heap region: ", kAsanHeapFreeMagic);
@@ -559,16 +559,16 @@ static void PrintShadowBytes(InternalScopedString *str, const char *before,
559559
u8 *bytes, u8 *guilty, uptr n) {
560560
Decorator d;
561561
if (before)
562-
str->append("%s%p:", before,
563-
(void *)ShadowToMem(reinterpret_cast<uptr>(bytes)));
562+
str->AppendF("%s%p:", before,
563+
(void *)ShadowToMem(reinterpret_cast<uptr>(bytes)));
564564
for (uptr i = 0; i < n; i++) {
565565
u8 *p = bytes + i;
566566
const char *before =
567567
p == guilty ? "[" : (p - 1 == guilty && i != 0) ? "" : " ";
568568
const char *after = p == guilty ? "]" : "";
569569
PrintShadowByte(str, before, *p, after);
570570
}
571-
str->append("\n");
571+
str->AppendF("\n");
572572
}
573573

574574
static void PrintShadowMemoryForAddress(uptr addr) {
@@ -577,7 +577,7 @@ static void PrintShadowMemoryForAddress(uptr addr) {
577577
const uptr n_bytes_per_row = 16;
578578
uptr aligned_shadow = shadow_addr & ~(n_bytes_per_row - 1);
579579
InternalScopedString str;
580-
str.append("Shadow bytes around the buggy address:\n");
580+
str.AppendF("Shadow bytes around the buggy address:\n");
581581
for (int i = -5; i <= 5; i++) {
582582
uptr row_shadow_addr = aligned_shadow + i * n_bytes_per_row;
583583
// Skip rows that would be outside the shadow range. This can happen when

compiler-rt/lib/asan/asan_fake_stack.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ void FakeStack::Destroy(int tid) {
6868
if (Verbosity() >= 2) {
6969
InternalScopedString str;
7070
for (uptr class_id = 0; class_id < kNumberOfSizeClasses; class_id++)
71-
str.append("%zd: %zd/%zd; ", class_id, hint_position_[class_id],
72-
NumberOfFrames(stack_size_log(), class_id));
71+
str.AppendF("%zd: %zd/%zd; ", class_id, hint_position_[class_id],
72+
NumberOfFrames(stack_size_log(), class_id));
7373
Report("T%d: FakeStack destroyed: %s\n", tid, str.data());
7474
}
7575
uptr size = RequiredSize(stack_size_log_);

compiler-rt/lib/asan/asan_globals.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,23 +295,26 @@ void PrintGlobalNameIfASCII(InternalScopedString *str, const __asan_global &g) {
295295
if (c == '\0' || !IsASCII(c)) return;
296296
}
297297
if (*(char *)(g.beg + g.size - 1) != '\0') return;
298-
str->append(" '%s' is ascii string '%s'\n", MaybeDemangleGlobalName(g.name),
299-
(char *)g.beg);
298+
str->AppendF(" '%s' is ascii string '%s'\n", MaybeDemangleGlobalName(g.name),
299+
(char *)g.beg);
300300
}
301301

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

306306
if (info.line != 0) {
307-
str->append("%s:%d", info.file, static_cast<int>(info.line));
307+
str->AppendF("%s:%d", info.file, static_cast<int>(info.line));
308308
} else if (g.gcc_location != 0) {
309309
// Fallback to Global::gcc_location
310-
str->append("%s", g.gcc_location->filename ? g.gcc_location->filename : g.module_name);
311-
if (g.gcc_location->line_no) str->append(":%d", g.gcc_location->line_no);
312-
if (g.gcc_location->column_no) str->append(":%d", g.gcc_location->column_no);
310+
str->AppendF("%s", g.gcc_location->filename ? g.gcc_location->filename
311+
: g.module_name);
312+
if (g.gcc_location->line_no)
313+
str->AppendF(":%d", g.gcc_location->line_no);
314+
if (g.gcc_location->column_no)
315+
str->AppendF(":%d", g.gcc_location->column_no);
313316
} else {
314-
str->append("%s", g.module_name);
317+
str->AppendF("%s", g.module_name);
315318
}
316319
}
317320

compiler-rt/lib/asan/asan_report.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ void AppendToErrorMessageBuffer(const char *buffer) {
6060
void PrintMemoryByte(InternalScopedString *str, const char *before, u8 byte,
6161
bool in_shadow, const char *after) {
6262
Decorator d;
63-
str->append("%s%s%x%x%s%s", before,
64-
in_shadow ? d.ShadowByte(byte) : d.MemoryByte(), byte >> 4,
65-
byte & 15, d.Default(), after);
63+
str->AppendF("%s%s%x%x%s%s", before,
64+
in_shadow ? d.ShadowByte(byte) : d.MemoryByte(), byte >> 4,
65+
byte & 15, d.Default(), after);
6666
}
6767

6868
static void PrintZoneForPointer(uptr ptr, uptr zone_ptr,

compiler-rt/lib/dfsan/dfsan.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -823,12 +823,12 @@ bool PrintOriginTraceFramesToStr(Origin o, InternalScopedString *out) {
823823
dfsan_origin origin_id = o.raw_id();
824824
o = o.getNextChainedOrigin(&stack);
825825
if (o.isChainedOrigin())
826-
out->append(
826+
out->AppendF(
827827
" %sOrigin value: 0x%x, Taint value was stored to memory at%s\n",
828828
d.Origin(), origin_id, d.Default());
829829
else
830-
out->append(" %sOrigin value: 0x%x, Taint value was created at%s\n",
831-
d.Origin(), origin_id, d.Default());
830+
out->AppendF(" %sOrigin value: 0x%x, Taint value was created at%s\n",
831+
d.Origin(), origin_id, d.Default());
832832

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

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

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

856856
Origin o = Origin::FromRawId(origin);
857857
return PrintOriginTraceFramesToStr(o, out);

compiler-rt/lib/hwasan/hwasan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static void HwasanFormatMemoryUsage(InternalScopedString &s) {
172172
auto sds = StackDepotGetStats();
173173
AllocatorStatCounters asc;
174174
GetAllocatorStats(asc);
175-
s.append(
175+
s.AppendF(
176176
"HWASAN pid: %d rss: %zd threads: %zd stacks: %zd"
177177
" thr_aux: %zd stack_depot: %zd uniq_stacks: %zd"
178178
" heap: %zd",

compiler-rt/lib/hwasan/hwasan_report.cpp

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ static void PrintStackAllocations(StackAllocationsRingBuffer *sa,
243243
break;
244244
uptr pc_mask = (1ULL << 48) - 1;
245245
uptr pc = record & pc_mask;
246-
frame_desc.append(" record_addr:0x%zx record:0x%zx",
247-
reinterpret_cast<uptr>(record_addr), record);
246+
frame_desc.AppendF(" record_addr:0x%zx record:0x%zx",
247+
reinterpret_cast<uptr>(record_addr), record);
248248
if (SymbolizedStack *frame = Symbolizer::GetOrInit()->SymbolizePC(pc)) {
249249
RenderFrame(&frame_desc, " %F %L", 0, frame->info.address, &frame->info,
250250
common_flags()->symbolize_vs_style,
@@ -528,14 +528,14 @@ static void PrintTagInfoAroundAddr(tag_t *tag_ptr, uptr num_rows,
528528
tag_t *end_row = center_row_beg + row_len * ((num_rows + 1) / 2);
529529
InternalScopedString s;
530530
for (tag_t *row = beg_row; row < end_row; row += row_len) {
531-
s.append("%s", row == center_row_beg ? "=>" : " ");
532-
s.append("%p:", (void *)ShadowToMem(reinterpret_cast<uptr>(row)));
531+
s.AppendF("%s", row == center_row_beg ? "=>" : " ");
532+
s.AppendF("%p:", (void *)ShadowToMem(reinterpret_cast<uptr>(row)));
533533
for (uptr i = 0; i < row_len; i++) {
534-
s.append("%s", row + i == tag_ptr ? "[" : " ");
534+
s.AppendF("%s", row + i == tag_ptr ? "[" : " ");
535535
print_tag(s, &row[i]);
536-
s.append("%s", row + i == tag_ptr ? "]" : " ");
536+
s.AppendF("%s", row + i == tag_ptr ? "]" : " ");
537537
}
538-
s.append("\n");
538+
s.AppendF("\n");
539539
}
540540
Printf("%s", s.data());
541541
}
@@ -545,7 +545,7 @@ static void PrintTagsAroundAddr(tag_t *tag_ptr) {
545545
"Memory tags around the buggy address (one tag corresponds to %zd "
546546
"bytes):\n", kShadowAlignment);
547547
PrintTagInfoAroundAddr(tag_ptr, 17, [](InternalScopedString &s, tag_t *tag) {
548-
s.append("%02x", *tag);
548+
s.AppendF("%02x", *tag);
549549
});
550550

551551
Printf(
@@ -555,10 +555,10 @@ static void PrintTagsAroundAddr(tag_t *tag_ptr) {
555555
PrintTagInfoAroundAddr(tag_ptr, 3, [](InternalScopedString &s, tag_t *tag) {
556556
if (*tag >= 1 && *tag <= kShadowAlignment) {
557557
uptr granule_addr = ShadowToMem(reinterpret_cast<uptr>(tag));
558-
s.append("%02x",
559-
*reinterpret_cast<u8 *>(granule_addr + kShadowAlignment - 1));
558+
s.AppendF("%02x",
559+
*reinterpret_cast<u8 *>(granule_addr + kShadowAlignment - 1));
560560
} else {
561-
s.append("..");
561+
s.AppendF("..");
562562
}
563563
});
564564
Printf(
@@ -654,31 +654,29 @@ void ReportTailOverwritten(StackTrace *stack, uptr tagged_addr, uptr orig_size,
654654
CHECK_GT(tail_size, 0U);
655655
CHECK_LT(tail_size, kShadowAlignment);
656656
u8 *tail = reinterpret_cast<u8*>(untagged_addr + orig_size);
657-
s.append("Tail contains: ");
658-
for (uptr i = 0; i < kShadowAlignment - tail_size; i++)
659-
s.append(".. ");
657+
s.AppendF("Tail contains: ");
658+
for (uptr i = 0; i < kShadowAlignment - tail_size; i++) s.AppendF(".. ");
659+
for (uptr i = 0; i < tail_size; i++) s.AppendF("%02x ", tail[i]);
660+
s.AppendF("\n");
661+
s.AppendF("Expected: ");
662+
for (uptr i = 0; i < kShadowAlignment - tail_size; i++) s.AppendF(".. ");
663+
for (uptr i = 0; i < tail_size; i++) s.AppendF("%02x ", actual_expected[i]);
664+
s.AppendF("\n");
665+
s.AppendF(" ");
666+
for (uptr i = 0; i < kShadowAlignment - tail_size; i++) s.AppendF(" ");
660667
for (uptr i = 0; i < tail_size; i++)
661-
s.append("%02x ", tail[i]);
662-
s.append("\n");
663-
s.append("Expected: ");
664-
for (uptr i = 0; i < kShadowAlignment - tail_size; i++)
665-
s.append(".. ");
666-
for (uptr i = 0; i < tail_size; i++) s.append("%02x ", actual_expected[i]);
667-
s.append("\n");
668-
s.append(" ");
669-
for (uptr i = 0; i < kShadowAlignment - tail_size; i++)
670-
s.append(" ");
671-
for (uptr i = 0; i < tail_size; i++)
672-
s.append("%s ", actual_expected[i] != tail[i] ? "^^" : " ");
673-
674-
s.append("\nThis error occurs when a buffer overflow overwrites memory\n"
675-
"after a heap object, but within the %zd-byte granule, e.g.\n"
676-
" char *x = new char[20];\n"
677-
" x[25] = 42;\n"
678-
"%s does not detect such bugs in uninstrumented code at the time of write,"
679-
"\nbut can detect them at the time of free/delete.\n"
680-
"To disable this feature set HWASAN_OPTIONS=free_checks_tail_magic=0\n",
681-
kShadowAlignment, SanitizerToolName);
668+
s.AppendF("%s ", actual_expected[i] != tail[i] ? "^^" : " ");
669+
670+
s.AppendF(
671+
"\nThis error occurs when a buffer overflow overwrites memory\n"
672+
"after a heap object, but within the %zd-byte granule, e.g.\n"
673+
" char *x = new char[20];\n"
674+
" x[25] = 42;\n"
675+
"%s does not detect such bugs in uninstrumented code at the time of "
676+
"write,"
677+
"\nbut can detect them at the time of free/delete.\n"
678+
"To disable this feature set HWASAN_OPTIONS=free_checks_tail_magic=0\n",
679+
kShadowAlignment, SanitizerToolName);
682680
Printf("%s", s.data());
683681
GetCurrentThread()->Announce();
684682

0 commit comments

Comments
 (0)