[compiler-rt] 4a37487 - [NFC][sanitizer] Replace a few AppendF with Append

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 15 23:03:35 PDT 2023


Author: Vitaly Buka
Date: 2023-09-15T23:03:19-07:00
New Revision: 4a3748769a5eeee13496cbffed6cc850e9b3f31e

URL: https://github.com/llvm/llvm-project/commit/4a3748769a5eeee13496cbffed6cc850e9b3f31e
DIFF: https://github.com/llvm/llvm-project/commit/4a3748769a5eeee13496cbffed6cc850e9b3f31e.diff

LOG: [NFC][sanitizer] Replace a few AppendF with Append

Added: 
    

Modified: 
    compiler-rt/lib/asan/asan_descriptions.cpp
    compiler-rt/lib/hwasan/hwasan_report.cpp
    compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp
    compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cpp
    compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.cpp
    compiler-rt/lib/ubsan/ubsan_diag.cpp
    compiler-rt/lib/ubsan/ubsan_monitor.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/asan/asan_descriptions.cpp b/compiler-rt/lib/asan/asan_descriptions.cpp
index 8bf070b36d0066b..5f3d15bcc9e2b0b 100644
--- a/compiler-rt/lib/asan/asan_descriptions.cpp
+++ b/compiler-rt/lib/asan/asan_descriptions.cpp
@@ -51,7 +51,7 @@ void DescribeThread(AsanThreadContext *context) {
   InternalScopedString str;
   str.AppendF("Thread %s", AsanThreadIdAndName(context).c_str());
   if (context->parent_tid == kInvalidTid) {
-    str.AppendF(" created by unknown thread\n");
+    str.Append(" created by unknown thread\n");
     Printf("%s", str.data());
     return;
   }
@@ -126,7 +126,7 @@ static void GetAccessToHeapChunkInformation(ChunkAccess *descr,
 static void PrintHeapChunkAccess(uptr addr, const ChunkAccess &descr) {
   Decorator d;
   InternalScopedString str;
-  str.AppendF("%s", d.Location());
+  str.Append(d.Location());
   switch (descr.access_type) {
     case kAccessTypeLeft:
       str.AppendF("%p is located %zd bytes before", (void *)descr.bad_addr,
@@ -148,7 +148,7 @@ static void PrintHeapChunkAccess(uptr addr, const ChunkAccess &descr) {
   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());
+  str.Append(d.Default());
   Printf("%s", str.data());
 }
 
@@ -277,7 +277,7 @@ static void DescribeAddressRelativeToGlobal(uptr addr, uptr access_size,
                                             const __asan_global &g) {
   InternalScopedString str;
   Decorator d;
-  str.AppendF("%s", d.Location());
+  str.Append(d.Location());
   if (addr < g.beg) {
     str.AppendF("%p is located %zd bytes before", (void *)addr, g.beg - addr);
   } else if (addr + access_size > g.beg + g.size) {
@@ -293,7 +293,7 @@ static void DescribeAddressRelativeToGlobal(uptr addr, uptr access_size,
               MaybeDemangleGlobalName(g.name));
   PrintGlobalLocation(&str, g);
   str.AppendF("' (0x%zx) of size %zu\n", g.beg, g.size);
-  str.AppendF("%s", d.Default());
+  str.Append(d.Default());
   PrintGlobalNameIfASCII(&str, g);
   Printf("%s", str.data());
 }

diff  --git a/compiler-rt/lib/hwasan/hwasan_report.cpp b/compiler-rt/lib/hwasan/hwasan_report.cpp
index 8d81322c35554c1..483f5b6ed59ea8a 100644
--- a/compiler-rt/lib/hwasan/hwasan_report.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_report.cpp
@@ -528,12 +528,12 @@ 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.AppendF("%s", row == center_row_beg ? "=>" : "  ");
+    s.Append(row == center_row_beg ? "=>" : "  ");
     s.AppendF("%p:", (void *)ShadowToMem(reinterpret_cast<uptr>(row)));
     for (uptr i = 0; i < row_len; i++) {
-      s.AppendF("%s", row + i == tag_ptr ? "[" : " ");
+      s.Append(row + i == tag_ptr ? "[" : " ");
       print_tag(s, &row[i]);
-      s.AppendF("%s", row + i == tag_ptr ? "]" : " ");
+      s.Append(row + i == tag_ptr ? "]" : " ");
     }
     s.AppendF("\n");
   }

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp
index b9a3117b48473fe..7b74bb1a7e0f3c5 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp
@@ -119,8 +119,10 @@ void MaybeStartBackgroudThread() {}
 #endif
 
 void WriteToSyslog(const char *msg) {
+  if (!msg)
+    return;
   InternalScopedString msg_copy;
-  msg_copy.AppendF("%s", msg);
+  msg_copy.Append(msg);
   const char *p = msg_copy.data();
 
   // Print one line at a time.

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cpp
index ef2c69c8a77af16..efbf7d9e450c63f 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cpp
@@ -63,8 +63,8 @@ class StackTraceTextPrinter {
     if (dedup_frames_-- > 0) {
       if (dedup_token_->length())
         dedup_token_->AppendF("--");
-      if (stack->info.function != nullptr)
-        dedup_token_->AppendF("%s", stack->info.function);
+      if (stack->info.function)
+        dedup_token_->Append(stack->info.function);
     }
   }
 

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.cpp
index 2c7540d7cf134ec..656f78a6186f44e 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.cpp
@@ -160,7 +160,7 @@ void RenderFrame(InternalScopedString *buffer, const char *format, int frame_no,
     p++;
     switch (*p) {
     case '%':
-      buffer->AppendF("%%");
+      buffer->Append("%");
       break;
     // Frame number and all fields of AddressInfo structure.
     case 'n':
@@ -283,7 +283,7 @@ void RenderData(InternalScopedString *buffer, const char *format,
     p++;
     switch (*p) {
       case '%':
-        buffer->AppendF("%%");
+        buffer->Append("%");
         break;
       case 's':
         buffer->AppendF("%s", StripPathPrefix(DI->file, strip_path_prefix));

diff  --git a/compiler-rt/lib/ubsan/ubsan_diag.cpp b/compiler-rt/lib/ubsan/ubsan_diag.cpp
index 3ab5d15b3d41398..9a0b02838239420 100644
--- a/compiler-rt/lib/ubsan/ubsan_diag.cpp
+++ b/compiler-rt/lib/ubsan/ubsan_diag.cpp
@@ -223,7 +223,7 @@ static void RenderText(InternalScopedString *Buffer, const char *Message,
 #else
       snprintf(FloatBuffer, sizeof(FloatBuffer), "%Lg", (long double)A.Float);
 #endif
-      Buffer->AppendF("%s", FloatBuffer);
+      Buffer->Append(FloatBuffer);
       break;
     }
     case Diag::AK_Pointer:
@@ -289,7 +289,7 @@ static void PrintMemorySnippet(const Decorator &Decor, MemoryLocation Loc,
   Buffer.AppendF("\n");
 
   // Emit highlights.
-  Buffer.AppendF("%s", Decor.Highlight());
+  Buffer.Append(Decor.Highlight());
   Range *InRange = upperBound(Min, Ranges, NumRanges);
   for (uptr P = Min; P != Max; ++P) {
     char Pad = ' ', Byte = ' ';
@@ -358,7 +358,7 @@ Diag::~Diag() {
     Buffer.clear();
   }
 
-  Buffer.AppendF("%s", Decor.Bold());
+  Buffer.Append(Decor.Bold());
   RenderLocation(&Buffer, Loc);
   Buffer.AppendF(":");
 

diff  --git a/compiler-rt/lib/ubsan/ubsan_monitor.cpp b/compiler-rt/lib/ubsan/ubsan_monitor.cpp
index 7aa786a864e9b1e..caed9726d48b22b 100644
--- a/compiler-rt/lib/ubsan/ubsan_monitor.cpp
+++ b/compiler-rt/lib/ubsan/ubsan_monitor.cpp
@@ -23,7 +23,8 @@ UndefinedBehaviorReport::UndefinedBehaviorReport(const char *IssueKind,
   RegisterUndefinedBehaviorReport(this);
 
   // Make a copy of the diagnostic.
-  Buffer.AppendF("%s", Msg.data());
+  if (Msg.length())
+    Buffer.Append(Msg.data());
 
   // Let the monitor know that a report is available.
   __ubsan_on_report();


        


More information about the llvm-commits mailing list