aras-p / ClangBuildAnalyzer

Clang build analysis tool using -ftime-trace
The Unlicense
969 stars 60 forks source link

Wrong printf format specifiers for int64_t #73

Closed randomascii closed 2 years ago

randomascii commented 3 years ago

In DebugPrintEvents %7ld is used to print a pair of int64_t values. When compiling with Visual Studio that leads to printf mismatch warnings because on Windows (32-bit or 64-bit) long is a 32-bit value.

I believe that %7lld is a portable 64-bit format value. It definitely works for 32-bit and 64-bit Windows processes. This is the updated line of code that I used to fix the warnings:

    printf("%4zi: t=%i t1=%7lld t2=%7lld par=%4i ch=%4zi det=%s\n", i, (int) event.type, event.ts, event.ts+event.dur, event.parent.idx, event.children.size(), std::string(names[event.detailIndex].substr(0,130)).c_str());
ben-craig commented 3 years ago

%lld is probably fine, but the pedantically correct thing is to use the PRId64 macro from <stdint.h> or <cstdint>. https://en.cppreference.com/w/cpp/types/integer

randomascii commented 3 years ago

Yep, good point.

aras-p commented 2 years ago

Should be fixed by #80 (merged into main branch, I'll tag the 1.2.0 release binaries soon)