Skip to content

Commit b44e6e0

Browse files
[NFC] Fix CodeQL violations in compiler-rt. (#157793)
This pull request addresses fixes against violations happening under subcategory 'cpp/wrong-type-format-argument' related to dfsan,fuzzer,hwasan.
1 parent 149b9ac commit b44e6e0

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

compiler-rt/lib/dfsan/dfsan.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,8 @@ static bool CheckMemoryRangeAvailability(uptr beg, uptr size, bool verbose) {
11281128
uptr end = beg + size - 1;
11291129
if (!MemoryRangeIsAvailable(beg, end)) {
11301130
if (verbose)
1131-
Printf("FATAL: Memory range %p - %p is not available.\n", beg, end);
1131+
Printf("FATAL: Memory range %p - %p is not available.\n", (void*)beg,
1132+
(void*)end);
11321133
return false;
11331134
}
11341135
}
@@ -1150,8 +1151,8 @@ static bool ProtectMemoryRange(uptr beg, uptr size, const char *name) {
11501151
}
11511152
if ((uptr)addr != beg) {
11521153
uptr end = beg + size - 1;
1153-
Printf("FATAL: Cannot protect memory range %p - %p (%s).\n", beg, end,
1154-
name);
1154+
Printf("FATAL: Cannot protect memory range %p - %p (%s).\n", (void*)beg,
1155+
(void*)end, name);
11551156
return false;
11561157
}
11571158
}
@@ -1172,7 +1173,7 @@ static bool InitShadow(bool init_origins, bool dry_run) {
11721173
if (!MEM_IS_APP(&__dfsan::dfsan_init)) {
11731174
if (!dry_run)
11741175
Printf("FATAL: Code %p is out of application range. Non-PIE build?\n",
1175-
(uptr)&__dfsan::dfsan_init);
1176+
(void*)&__dfsan::dfsan_init);
11761177
return false;
11771178
}
11781179

compiler-rt/lib/fuzzer/FuzzerCorpus.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ class InputCorpus {
336336
void PrintFeatureSet() {
337337
for (size_t i = 0; i < kFeatureSetSize; i++) {
338338
if(size_t Sz = GetFeature(i))
339-
Printf("[%zd: id %zd sz%zd] ", i, SmallestElementPerFeature[i], Sz);
339+
Printf("[%zd: id %zd sz%zd] ", i, (size_t)SmallestElementPerFeature[i],
340+
Sz);
340341
}
341342
Printf("\n\t");
342343
for (size_t i = 0; i < Inputs.size(); i++)

compiler-rt/lib/fuzzer/FuzzerDriver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,13 @@ static bool ParseOneFlag(const char *Param) {
163163
auto Val = MyStol(Str);
164164
*FlagDescriptions[F].IntFlag = static_cast<int>(Val);
165165
if (Flags.verbosity >= 2)
166-
Printf("Flag: %s %d\n", Name, Val);
166+
Printf("Flag: %s %d\n", Name, (int)Val);
167167
return true;
168168
} else if (FlagDescriptions[F].UIntFlag) {
169169
auto Val = std::stoul(Str);
170170
*FlagDescriptions[F].UIntFlag = static_cast<unsigned int>(Val);
171171
if (Flags.verbosity >= 2)
172-
Printf("Flag: %s %u\n", Name, Val);
172+
Printf("Flag: %s %u\n", Name, (uint)Val);
173173
return true;
174174
} else if (FlagDescriptions[F].StrFlag) {
175175
*FlagDescriptions[F].StrFlag = Str;

compiler-rt/lib/fuzzer/FuzzerLoop.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ void FreeHook(const volatile void *ptr) {
125125
void Fuzzer::HandleMalloc(size_t Size) {
126126
if (!Options.MallocLimitMb || (Size >> 20) < (size_t)Options.MallocLimitMb)
127127
return;
128-
Printf("==%d== ERROR: libFuzzer: out-of-memory (malloc(%zd))\n", GetPid(),
129-
Size);
128+
Printf("==%d== ERROR: libFuzzer: out-of-memory (malloc(%zd))\n",
129+
(int)GetPid(), Size);
130130
Printf(" To change the out-of-memory limit use -rss_limit_mb=<N>\n\n");
131131
PrintStackTrace();
132132
DumpCurrentUnit("oom-");
@@ -568,7 +568,7 @@ size_t Fuzzer::GetCurrentUnitInFuzzingThead(const uint8_t **Data) const {
568568

569569
void Fuzzer::CrashOnOverwrittenData() {
570570
Printf("==%d== ERROR: libFuzzer: fuzz target overwrites its const input\n",
571-
GetPid());
571+
(int)GetPid());
572572
PrintStackTrace();
573573
Printf("SUMMARY: libFuzzer: overwrites-const-input\n");
574574
DumpCurrentUnit("crash-");

compiler-rt/lib/hwasan/hwasan_report.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -738,9 +738,9 @@ void BaseReport::PrintHeapOrGlobalCandidate() const {
738738
Printf("%s", d.Default());
739739
Printf("%s", d.Location());
740740
Printf("%p is located %zd bytes %s a %zd-byte region [%p,%p)\n",
741-
untagged_addr, offset, whence,
741+
(void*)untagged_addr, offset, whence,
742742
candidate.heap.end - candidate.heap.begin,
743-
(void *)candidate.heap.begin, (void *)candidate.heap.end);
743+
(void*)candidate.heap.begin, (void*)candidate.heap.end);
744744
Printf("%s", d.Allocation());
745745
Printf("allocated by thread T%u here:\n", candidate.heap.thread_id);
746746
Printf("%s", d.Default());
@@ -775,14 +775,14 @@ void BaseReport::PrintHeapOrGlobalCandidate() const {
775775
Printf(
776776
"%p is located %s a global variable in "
777777
"\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);
778+
(void*)untagged_addr, candidate.after ? "after" : "before",
779+
(u32)candidate.untagged_addr, module_name, (u32)module_address);
780780
else
781781
Printf(
782782
"%p is located %s a %zd-byte global variable in "
783783
"\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);
784+
(void*)untagged_addr, candidate.after ? "after" : "before", size,
785+
(u32)candidate.untagged_addr, module_name, (u32)module_address);
786786
}
787787
Printf("%s", d.Default());
788788
}
@@ -843,9 +843,9 @@ void BaseReport::PrintAddressDescription() const {
843843
Printf("\nCause: use-after-free\n");
844844
Printf("%s", d.Location());
845845
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));
846+
(void*)untagged_addr, untagged_addr - UntagAddr(har.tagged_addr),
847+
(ssize)har.requested_size, (void*)UntagAddr(har.tagged_addr),
848+
(void*)(UntagAddr(har.tagged_addr) + har.requested_size));
849849
Printf("%s", d.Allocation());
850850
Printf("freed by thread T%u here:\n", ha.free_thread_id);
851851
Printf("%s", d.Default());

0 commit comments

Comments
 (0)