Skip to content

Commit ee5367b

Browse files
committed
Revert "[compiler-rt]: fix CodeQL format-string warnings via explicit casts (#153843)"
It broke the build: compiler-rt/lib/hwasan/hwasan_thread.cpp:177:11: error: unknown type name 'ssize_t'; did you mean 'size_t'? 177 | (ssize_t)unique_id_, (void *)this, (void *)stack_bottom(), | ^~~~~~~ | size_t > This change addresses CodeQL format-string warnings across multiple > sanitizer libraries by adding explicit casts to ensure that printf-style > format specifiers match the actual argument types. > > Key updates: > - Cast pointer arguments to (void*) when used with %p. > - Use appropriate integer types and specifiers (e.g., size_t -> %zu, > ssize_t -> %zd) to avoid mismatches. > - Fix format specifier mismatches across xray, memprof, lsan, hwasan, > dfsan. > > These changes are no-ops at runtime but improve type safety, silence > static analysis warnings, and reduce the risk of UB in variadic calls. This reverts commit d3d5751.
1 parent d5af08a commit ee5367b

File tree

9 files changed

+39
-44
lines changed

9 files changed

+39
-44
lines changed

compiler-rt/lib/dfsan/dfsan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ static void PrintNoOriginTrackingWarning() {
792792

793793
static void PrintNoTaintWarning(const void *address) {
794794
Decorator d;
795-
Printf(" %sDFSan: no tainted value at %zx%s\n", d.Warning(), (uptr)address,
795+
Printf(" %sDFSan: no tainted value at %x%s\n", d.Warning(), address,
796796
d.Default());
797797
}
798798

compiler-rt/lib/hwasan/hwasan.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static void HwasanFormatMemoryUsage(InternalScopedString &s) {
176176
"HWASAN pid: %d rss: %zd threads: %zd stacks: %zd"
177177
" thr_aux: %zd stack_depot: %zd uniq_stacks: %zd"
178178
" heap: %zd",
179-
(int)internal_getpid(), GetRSS(), thread_stats.n_live_threads,
179+
internal_getpid(), GetRSS(), thread_stats.n_live_threads,
180180
thread_stats.total_stack_size,
181181
thread_stats.n_live_threads * thread_list.MemoryUsedPerThread(),
182182
sds.allocated, sds.n_uniq_ids, asc[AllocatorStatMapped]);
@@ -692,7 +692,7 @@ void __hwasan_handle_longjmp(const void *sp_dst) {
692692
"WARNING: HWASan is ignoring requested __hwasan_handle_longjmp: "
693693
"stack top: %p; target %p; distance: %p (%zd)\n"
694694
"False positive error reports may follow\n",
695-
(void *)sp, (void *)dst, (void *)(dst - sp), dst - sp);
695+
(void *)sp, (void *)dst, dst - sp, dst - sp);
696696
return;
697697
}
698698
TagMemory(sp, dst - sp, 0);

compiler-rt/lib/hwasan/hwasan_malloc_bisect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static inline bool malloc_bisect(StackTrace *stack, uptr orig_size) {
4141
if (h < left || h > right)
4242
return false;
4343
if (flags()->malloc_bisect_dump) {
44-
Printf("[alloc] %u %zu\n", (u32)h, orig_size);
44+
Printf("[alloc] %u %zu\n", h, orig_size);
4545
stack->Print();
4646
}
4747
return true;

compiler-rt/lib/hwasan/hwasan_report.cpp

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,8 @@ static void PrintStackAllocations(const StackAllocationsRingBuffer *sa,
306306
"%p is located %zd bytes %s a %zd-byte local variable %s "
307307
"[%p,%p) "
308308
"in %s %s\n",
309-
(void *)untagged_addr, offset, whence, local.size, local.name,
310-
(void *)best_beg, (void *)(best_beg + local.size),
311-
local.function_name, location.data());
309+
untagged_addr, offset, whence, local.size, local.name, best_beg,
310+
best_beg + local.size, local.function_name, location.data());
312311
location.clear();
313312
Printf("%s\n", d.Default());
314313
}
@@ -739,8 +738,8 @@ void BaseReport::PrintHeapOrGlobalCandidate() const {
739738
Printf("%s", d.Location());
740739
Printf("%p is located %zd bytes %s a %zd-byte region [%p,%p)\n",
741740
untagged_addr, offset, whence,
742-
candidate.heap.end - candidate.heap.begin,
743-
(void *)candidate.heap.begin, (void *)candidate.heap.end);
741+
candidate.heap.end - candidate.heap.begin, candidate.heap.begin,
742+
candidate.heap.end);
744743
Printf("%s", d.Allocation());
745744
Printf("allocated by thread T%u here:\n", candidate.heap.thread_id);
746745
Printf("%s", d.Default());
@@ -763,26 +762,26 @@ void BaseReport::PrintHeapOrGlobalCandidate() const {
763762
Printf(
764763
"%p is located %zd bytes %s a %zd-byte global variable "
765764
"%s [%p,%p) in %s\n",
766-
(void *)untagged_addr,
765+
untagged_addr,
767766
candidate.after ? untagged_addr - (info.start + info.size)
768767
: info.start - untagged_addr,
769768
candidate.after ? "after" : "before", info.size, info.name,
770-
(void *)info.start, (void *)(info.start + info.size), module_name);
769+
info.start, info.start + info.size, module_name);
771770
} else {
772771
uptr size = GetGlobalSizeFromDescriptor(candidate.untagged_addr);
773772
if (size == 0)
774773
// We couldn't find the size of the global from the descriptors.
775774
Printf(
776775
"%p is located %s a global variable in "
777776
"\n #0 0x%x (%s+0x%x)\n",
778-
(void *)untagged_addr, candidate.after ? "after" : "before",
779-
(void *)candidate.untagged_addr, module_name, (u32)module_address);
777+
untagged_addr, candidate.after ? "after" : "before",
778+
candidate.untagged_addr, module_name, module_address);
780779
else
781780
Printf(
782781
"%p is located %s a %zd-byte global variable in "
783782
"\n #0 0x%x (%s+0x%x)\n",
784-
(void *)untagged_addr, candidate.after ? "after" : "before", size,
785-
(void *)candidate.untagged_addr, module_name, (u32)module_address);
783+
untagged_addr, candidate.after ? "after" : "before", size,
784+
candidate.untagged_addr, module_name, module_address);
786785
}
787786
Printf("%s", d.Default());
788787
}
@@ -793,8 +792,8 @@ void BaseReport::PrintAddressDescription() const {
793792
int num_descriptions_printed = 0;
794793

795794
if (MemIsShadow(untagged_addr)) {
796-
Printf("%s%p is HWAsan shadow memory.\n%s", d.Location(),
797-
(void *)untagged_addr, d.Default());
795+
Printf("%s%p is HWAsan shadow memory.\n%s", d.Location(), untagged_addr,
796+
d.Default());
798797
return;
799798
}
800799

@@ -803,7 +802,7 @@ void BaseReport::PrintAddressDescription() const {
803802
Printf(
804803
"%s[%p,%p) is a %s %s heap chunk; "
805804
"size: %zd offset: %zd\n%s",
806-
d.Location(), (void *)heap.begin, (void *)(heap.begin + heap.size),
805+
d.Location(), heap.begin, heap.begin + heap.size,
807806
heap.from_small_heap ? "small" : "large",
808807
heap.is_allocated ? "allocated" : "unallocated", heap.size,
809808
untagged_addr - heap.begin, d.Default());
@@ -822,8 +821,8 @@ void BaseReport::PrintAddressDescription() const {
822821
Printf("%s", d.Error());
823822
Printf("\nCause: stack tag-mismatch\n");
824823
Printf("%s", d.Location());
825-
Printf("Address %p is located in stack of thread T%zd\n",
826-
(void *)untagged_addr, (ssize)sa.thread_id());
824+
Printf("Address %p is located in stack of thread T%zd\n", untagged_addr,
825+
sa.thread_id());
827826
Printf("%s", d.Default());
828827
announce_by_id(sa.thread_id());
829828
PrintStackAllocations(sa.get(), ptr_tag, untagged_addr);
@@ -843,9 +842,9 @@ void BaseReport::PrintAddressDescription() const {
843842
Printf("\nCause: use-after-free\n");
844843
Printf("%s", d.Location());
845844
Printf("%p is located %zd bytes inside a %zd-byte region [%p,%p)\n",
846-
(void *)untagged_addr, untagged_addr - UntagAddr(har.tagged_addr),
847-
(ssize)har.requested_size, UntagAddr(har.tagged_addr),
848-
(void *)(UntagAddr(har.tagged_addr) + har.requested_size));
845+
untagged_addr, untagged_addr - UntagAddr(har.tagged_addr),
846+
har.requested_size, UntagAddr(har.tagged_addr),
847+
UntagAddr(har.tagged_addr) + har.requested_size);
849848
Printf("%s", d.Allocation());
850849
Printf("freed by thread T%u here:\n", ha.free_thread_id);
851850
Printf("%s", d.Default());
@@ -859,7 +858,7 @@ void BaseReport::PrintAddressDescription() const {
859858
// Print a developer note: the index of this heap object
860859
// in the thread's deallocation ring buffer.
861860
Printf("hwasan_dev_note_heap_rb_distance: %zd %zd\n", ha.ring_index + 1,
862-
(ssize)flags()->heap_history_size);
861+
flags()->heap_history_size);
863862
Printf("hwasan_dev_note_num_matching_addrs: %zd\n", ha.num_matching_addrs);
864863
Printf("hwasan_dev_note_num_matching_addrs_4b: %zd\n",
865864
ha.num_matching_addrs_4b);
@@ -916,11 +915,10 @@ InvalidFreeReport::~InvalidFreeReport() {
916915
const Thread *thread = GetCurrentThread();
917916
if (thread) {
918917
Report("ERROR: %s: %s on address %p at pc %p on thread T%zd\n",
919-
SanitizerToolName, bug_type, (void *)untagged_addr, (void *)pc,
920-
(ssize)thread->unique_id());
918+
SanitizerToolName, bug_type, untagged_addr, pc, thread->unique_id());
921919
} else {
922920
Report("ERROR: %s: %s on address %p at pc %p on unknown thread\n",
923-
SanitizerToolName, bug_type, (void *)untagged_addr, (void *)pc);
921+
SanitizerToolName, bug_type, untagged_addr, pc);
924922
}
925923
Printf("%s", d.Access());
926924
if (shadow.addr) {
@@ -969,8 +967,7 @@ TailOverwrittenReport::~TailOverwrittenReport() {
969967
Printf("%s", d.Error());
970968
const char *bug_type = "allocation-tail-overwritten";
971969
Report("ERROR: %s: %s; heap object [%p,%p) of size %zd\n", SanitizerToolName,
972-
bug_type, (void *)untagged_addr, (void *)(untagged_addr + orig_size),
973-
orig_size);
970+
bug_type, untagged_addr, untagged_addr + orig_size, orig_size);
974971
Printf("\n%s", d.Default());
975972
Printf(
976973
"Stack of invalid access unknown. Issue detected at deallocation "
@@ -1040,7 +1037,7 @@ TagMismatchReport::~TagMismatchReport() {
10401037
uptr pc = GetTopPc(stack);
10411038
Printf("%s", d.Error());
10421039
Report("ERROR: %s: %s on address %p at pc %p\n", SanitizerToolName, bug_type,
1043-
(void *)untagged_addr, (void *)pc);
1040+
untagged_addr, pc);
10441041

10451042
Thread *t = GetCurrentThread();
10461043

@@ -1052,12 +1049,12 @@ TagMismatchReport::~TagMismatchReport() {
10521049
GetShortTagCopy(MemToShadow(untagged_addr + mismatch_offset));
10531050
Printf(
10541051
"%s of size %zu at %p tags: %02x/%02x(%02x) (ptr/mem) in thread T%zd\n",
1055-
is_store ? "WRITE" : "READ", access_size, (void *)untagged_addr,
1056-
ptr_tag, mem_tag, short_tag, (ssize)t->unique_id());
1052+
is_store ? "WRITE" : "READ", access_size, untagged_addr, ptr_tag,
1053+
mem_tag, short_tag, t->unique_id());
10571054
} else {
10581055
Printf("%s of size %zu at %p tags: %02x/%02x (ptr/mem) in thread T%zd\n",
1059-
is_store ? "WRITE" : "READ", access_size, (void *)untagged_addr,
1060-
ptr_tag, mem_tag, (ssize)t->unique_id());
1056+
is_store ? "WRITE" : "READ", access_size, untagged_addr, ptr_tag,
1057+
mem_tag, t->unique_id());
10611058
}
10621059
if (mismatch_offset)
10631060
Printf("Invalid access starting at offset %zu\n", mismatch_offset);
@@ -1096,7 +1093,7 @@ void ReportTagMismatch(StackTrace *stack, uptr tagged_addr, uptr access_size,
10961093
// See the frame breakdown defined in __hwasan_tag_mismatch (from
10971094
// hwasan_tag_mismatch_{aarch64,riscv64}.S).
10981095
void ReportRegisters(const uptr *frame, uptr pc) {
1099-
Printf("\nRegisters where the failure occurred (pc %p):\n", (void *)pc);
1096+
Printf("\nRegisters where the failure occurred (pc %p):\n", pc);
11001097

11011098
// We explicitly print a single line (4 registers/line) each iteration to
11021099
// reduce the amount of logcat error messages printed. Each Printf() will

compiler-rt/lib/hwasan/hwasan_thread.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,9 @@ uptr Thread::stack_size() {
173173
}
174174

175175
void Thread::Print(const char *Prefix) {
176-
Printf("%sT%zd %p stack: [%p,%p) sz: %zd tls: [%p,%p)\n", Prefix,
177-
(ssize_t)unique_id_, (void *)this, (void *)stack_bottom(),
178-
(void *)stack_top(), stack_top() - stack_bottom(), (void *)tls_begin(),
179-
(void *)tls_end());
176+
Printf("%sT%zd %p stack: [%p,%p) sz: %zd tls: [%p,%p)\n", Prefix, unique_id_,
177+
(void *)this, stack_bottom(), stack_top(),
178+
stack_top() - stack_bottom(), tls_begin(), tls_end());
180179
}
181180

182181
static u32 xorshift(u32 state) {

compiler-rt/lib/lsan/lsan_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ static bool ReportUnsuspendedThreads(
806806
succeded = false;
807807
Report(
808808
"Running thread %zu was not suspended. False leaks are possible.\n",
809-
(usize)os_id);
809+
os_id);
810810
}
811811
}
812812
return succeded;

compiler-rt/lib/memprof/memprof_shadow_setup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static void ProtectGap(uptr addr, uptr size) {
2929
Printf("protect_shadow_gap=0:"
3030
" not protecting shadow gap, allocating gap's shadow\n"
3131
"|| `[%p, %p]` || ShadowGap's shadow ||\n",
32-
(void *)GapShadowBeg, (void *)GapShadowEnd);
32+
GapShadowBeg, GapShadowEnd);
3333
ReserveShadowMemoryRange(GapShadowBeg, GapShadowEnd,
3434
"unprotected gap shadow");
3535
return;

compiler-rt/lib/xray/xray_init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ __xray_register_sleds(const XRaySledEntry *SledsBegin,
105105
}
106106

107107
if (Verbosity())
108-
Report("Registering %d new functions!\n", (int)SledMap.Functions);
108+
Report("Registering %d new functions!\n", SledMap.Functions);
109109

110110
{
111111
SpinMutexLock Guard(&XRayInstrMapMutex);

compiler-rt/lib/xray/xray_interface.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,7 @@ XRayPatchingStatus controlPatchingObjectUnchecked(bool Enable, int32_t ObjId) {
308308
return XRayPatchingStatus::NOT_INITIALIZED;
309309

310310
if (Verbosity())
311-
Report("Patching object %d with %d functions.\n", ObjId,
312-
(int)InstrMap.Entries);
311+
Report("Patching object %d with %d functions.\n", ObjId, InstrMap.Entries);
313312

314313
// Check if the corresponding DSO has been unloaded.
315314
if (!InstrMap.Loaded) {

0 commit comments

Comments
 (0)