PixarAnimationStudios / OpenUSD

Universal Scene Description
http://www.openusd.org
Other
6.03k stars 1.2k forks source link

Compiler Warnings: Incorrect format specifiers #3336

Open dgovil opened 2 days ago

dgovil commented 2 days ago

Description of Issue

Various places in the USD codebase use an incorrect format specifier for the given input type. I think this would be a good first issue for a contributor to get started with developing for USD, and reduce the risk of bugs in the codebase at the same time.

I am building with Clang 16 from Xcode 16 with python3 ./build_scripts/build_usd.py ~/Downloads/usd --build-variant debug --no-imaging -vvv but this should reproduce with other compilers. The warnings are reproduced below:

[2272/4632] Building CXX object pxr/usd/usd/CMakeFiles/usd.dir/crateFile.cpp.o
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/crateFile.cpp:3597:26: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'unsigned long long' [-Wformat]
 3596 |         TF_RUNTIME_ERROR("Crate file claims %zu tokens, found %zu",
      |                                             ~~~
      |                                             %llu
 3597 |                          numTokens, i);
      |                          ^~~~~~~~~
/Users/dhruvgovil/Projects/usd/pxr/base/tf/diagnostic.h:336:43: note: expanded from macro 'TF_RUNTIME_ERROR'
  336 |         TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE, __VA_ARGS__)
      |                                           ^~~~~~~~~~~
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/crateFile.cpp:3227:26: note: in instantiation of function template specialization 'pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_ReadTokens<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_Reader<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::_MmapStream<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_FileMapping *>>>' requested here
 3227 |         if (m.IsClean()) _ReadTokens(reader);
      |                          ^
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/crateFile.cpp:2315:9: note: in instantiation of function template specialization 'pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_ReadStructuralSections<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_Reader<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::_MmapStream<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_FileMapping *>>>' requested here
 2315 |         _ReadStructuralSections(reader, mapSize);
      |         ^
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/crateFile.cpp:3597:26: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'unsigned long long' [-Wformat]
 3596 |         TF_RUNTIME_ERROR("Crate file claims %zu tokens, found %zu",
      |                                             ~~~
      |                                             %llu
 3597 |                          numTokens, i);
      |                          ^~~~~~~~~
/Users/dhruvgovil/Projects/usd/pxr/base/tf/diagnostic.h:336:43: note: expanded from macro 'TF_RUNTIME_ERROR'
  336 |         TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE, __VA_ARGS__)
      |                                           ^~~~~~~~~~~
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/crateFile.cpp:3227:26: note: in instantiation of function template specialization 'pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_ReadTokens<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_Reader<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::_PreadStream>>' requested here
 3227 |         if (m.IsClean()) _ReadTokens(reader);
      |                          ^
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/crateFile.cpp:2354:5: note: in instantiation of function template specialization 'pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_ReadStructuralSections<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_Reader<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::_PreadStream>>' requested here
 2354 |     _ReadStructuralSections(reader, rangeLength);
      |     ^
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/crateFile.cpp:3597:26: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'unsigned long long' [-Wformat]
 3596 |         TF_RUNTIME_ERROR("Crate file claims %zu tokens, found %zu",
      |                                             ~~~
      |                                             %llu
 3597 |                          numTokens, i);
      |                          ^~~~~~~~~
/Users/dhruvgovil/Projects/usd/pxr/base/tf/diagnostic.h:336:43: note: expanded from macro 'TF_RUNTIME_ERROR'
  336 |         TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE, __VA_ARGS__)
      |                                           ^~~~~~~~~~~
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/crateFile.cpp:3227:26: note: in instantiation of function template specialization 'pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_ReadTokens<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_Reader<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::_AssetStream>>' requested here
 3227 |         if (m.IsClean()) _ReadTokens(reader);
      |                          ^
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/crateFile.cpp:2379:5: note: in instantiation of function template specialization 'pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_ReadStructuralSections<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_Reader<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::_AssetStream>>' requested here
 2379 |     _ReadStructuralSections(reader, _assetSrc->GetSize());
      |     ^
3 warnings generated.
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/crateFile.cpp:3597:26: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'unsigned long long' [-Wformat]
 3596 |         TF_RUNTIME_ERROR("Crate file claims %zu tokens, found %zu",
      |                                             ~~~
      |                                             %llu
 3597 |                          numTokens, i);
      |                          ^~~~~~~~~
/Users/dhruvgovil/Projects/usd/pxr/base/tf/diagnostic.h:336:43: note: expanded from macro 'TF_RUNTIME_ERROR'
  336 |         TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE, __VA_ARGS__)
      |                                           ^~~~~~~~~~~
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/crateFile.cpp:3227:26: note: in instantiation of function template specialization 'pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_ReadTokens<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_Reader<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::_MmapStream<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_FileMapping *>>>' requested here
 3227 |         if (m.IsClean()) _ReadTokens(reader);
      |                          ^
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/crateFile.cpp:2315:9: note: in instantiation of function template specialization 'pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_ReadStructuralSections<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_Reader<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::_MmapStream<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_FileMapping *>>>' requested here
 2315 |         _ReadStructuralSections(reader, mapSize);
      |         ^
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/crateFile.cpp:3597:26: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'unsigned long long' [-Wformat]
 3596 |         TF_RUNTIME_ERROR("Crate file claims %zu tokens, found %zu",
      |                                             ~~~
      |                                             %llu
 3597 |                          numTokens, i);
      |                          ^~~~~~~~~
/Users/dhruvgovil/Projects/usd/pxr/base/tf/diagnostic.h:336:43: note: expanded from macro 'TF_RUNTIME_ERROR'
  336 |         TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE, __VA_ARGS__)
      |                                           ^~~~~~~~~~~
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/crateFile.cpp:3227:26: note: in instantiation of function template specialization 'pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_ReadTokens<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_Reader<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::_PreadStream>>' requested here
 3227 |         if (m.IsClean()) _ReadTokens(reader);
      |                          ^
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/crateFile.cpp:2354:5: note: in instantiation of function template specialization 'pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_ReadStructuralSections<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_Reader<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::_PreadStream>>' requested here
 2354 |     _ReadStructuralSections(reader, rangeLength);
      |     ^
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/crateFile.cpp:3597:26: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'unsigned long long' [-Wformat]
 3596 |         TF_RUNTIME_ERROR("Crate file claims %zu tokens, found %zu",
      |                                             ~~~
      |                                             %llu
 3597 |                          numTokens, i);
      |                          ^~~~~~~~~
/Users/dhruvgovil/Projects/usd/pxr/base/tf/diagnostic.h:336:43: note: expanded from macro 'TF_RUNTIME_ERROR'
  336 |         TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE, __VA_ARGS__)
      |                                           ^~~~~~~~~~~
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/crateFile.cpp:3227:26: note: in instantiation of function template specialization 'pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_ReadTokens<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_Reader<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::_AssetStream>>' requested here
 3227 |         if (m.IsClean()) _ReadTokens(reader);
      |                          ^
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/crateFile.cpp:2379:5: note: in instantiation of function template specialization 'pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_ReadStructuralSections<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::CrateFile::_Reader<pxrInternal_v0_24_11__pxrReserved__::Usd_CrateFile::_AssetStream>>' requested here
 2379 |     _ReadStructuralSections(reader, _assetSrc->GetSize());
      |     ^
3 warnings generated.

[3506/4632] Building CXX object pxr/base/arch/CMakeFiles/testArchPRead.dir/testenv/testArchPRead.cpp.o
/Users/dhruvgovil/Projects/usd/pxr/base/arch/testenv/testArchPRead.cpp:45:61: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'int64_t' (aka 'long long') [-Wformat]
   45 |     printf("Reading %s (%zu bytes)...\n", filename.c_str(), fileSize);
      |                         ~~~                                 ^~~~~~~~
      |                         %lld
/Users/dhruvgovil/Projects/usd/pxr/base/arch/testenv/testArchPRead.cpp:50:57: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'int64_t' (aka 'long long') [-Wformat]
   50 |         printf("ERROR: Read %zu bytes, expected %zu\n", numRead, fileSize);
      |                             ~~~                         ^~~~~~~
      |                             %lld
/Users/dhruvgovil/Projects/usd/pxr/base/arch/testenv/testArchPRead.cpp:50:66: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'int64_t' (aka 'long long') [-Wformat]
   50 |         printf("ERROR: Read %zu bytes, expected %zu\n", numRead, fileSize);
      |                                                 ~~~              ^~~~~~~~
      |                                                 %lld
3 warnings generated.
/Users/dhruvgovil/Projects/usd/pxr/base/arch/testenv/testArchPRead.cpp:45:61: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'int64_t' (aka 'long long') [-Wformat]
   45 |     printf("Reading %s (%zu bytes)...\n", filename.c_str(), fileSize);
      |                         ~~~                                 ^~~~~~~~
      |                         %lld
/Users/dhruvgovil/Projects/usd/pxr/base/arch/testenv/testArchPRead.cpp:50:57: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'int64_t' (aka 'long long') [-Wformat]
   50 |         printf("ERROR: Read %zu bytes, expected %zu\n", numRead, fileSize);
      |                             ~~~                         ^~~~~~~
      |                             %lld
/Users/dhruvgovil/Projects/usd/pxr/base/arch/testenv/testArchPRead.cpp:50:66: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'int64_t' (aka 'long long') [-Wformat]
   50 |         printf("ERROR: Read %zu bytes, expected %zu\n", numRead, fileSize);
      |                                                 ~~~              ^~~~~~~~
      |                                                 %lld
3 warnings generated.
[3553/4632] Building CXX object pxr/base/tf/CMakeFiles/testTf.dir/testenv/hash.cpp.o
/Users/dhruvgovil/Projects/usd/pxr/base/tf/testenv/hash.cpp:103:43: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'uint64_t' (aka 'unsigned long long') [-Wformat]
  103 |     printf("%s One: %zu tests.\n", label, NTESTS * 64);
      |                     ~~~                   ^~~~~~~~~~~
      |                     %llu
/Users/dhruvgovil/Projects/usd/pxr/base/tf/testenv/hash.cpp:304:5: note: in instantiation of function template specialization '_TestStatsOne<TfHasher>' requested here
  304 |     _TestStatsOne(tfh, "TfHash");
      |     ^
/Users/dhruvgovil/Projects/usd/pxr/base/tf/testenv/hash.cpp:131:43: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'uint64_t' (aka 'unsigned long long') [-Wformat]
  131 |     printf("%s Two: %zu tests.\n", label, NTESTS * 64);
      |                     ~~~                   ^~~~~~~~~~~
      |                     %llu
/Users/dhruvgovil/Projects/usd/pxr/base/tf/testenv/hash.cpp:305:5: note: in instantiation of function template specialization '_TestStatsTwo<TfHasher>' requested here
  305 |     _TestStatsTwo(tfh, "TfHash");
      |     ^
2 warnings generated.
/Users/dhruvgovil/Projects/usd/pxr/base/tf/testenv/hash.cpp:103:43: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'uint64_t' (aka 'unsigned long long') [-Wformat]
  103 |     printf("%s One: %zu tests.\n", label, NTESTS * 64);
      |                     ~~~                   ^~~~~~~~~~~
      |                     %llu
/Users/dhruvgovil/Projects/usd/pxr/base/tf/testenv/hash.cpp:304:5: note: in instantiation of function template specialization '_TestStatsOne<TfHasher>' requested here
  304 |     _TestStatsOne(tfh, "TfHash");
      |     ^
/Users/dhruvgovil/Projects/usd/pxr/base/tf/testenv/hash.cpp:131:43: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'uint64_t' (aka 'unsigned long long') [-Wformat]
  131 |     printf("%s Two: %zu tests.\n", label, NTESTS * 64);
      |                     ~~~                   ^~~~~~~~~~~
      |                     %llu
/Users/dhruvgovil/Projects/usd/pxr/base/tf/testenv/hash.cpp:305:5: note: in instantiation of function template specialization '_TestStatsTwo<TfHasher>' requested here
  305 |     _TestStatsTwo(tfh, "TfHash");
      |     ^
2 warnings generated.

[3713/4632] Building CXX object pxr/base/trace/CMakeFiles/_trace.dir/wrapCollector.cpp.o
/Users/dhruvgovil/Projects/usd/pxr/base/trace/wrapCollector.cpp:30:65: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'TraceEvent::TimeStamp' (aka 'unsigned long long') [-Wformat]
   30 |         TF_CODING_ERROR("Invalid interval: begin=%zu, end=%zu", begin, end);
      |                                                  ~~~            ^~~~~
      |                                                  %llu
/Users/dhruvgovil/Projects/usd/pxr/base/tf/diagnostic.h:307:42: note: expanded from macro 'TF_CODING_ERROR'
  307 |         TF_DIAGNOSTIC_CODING_ERROR_TYPE, __VA_ARGS__)
      |                                          ^~~~~~~~~~~
/Users/dhruvgovil/Projects/usd/pxr/base/trace/wrapCollector.cpp:30:72: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'TraceEvent::TimeStamp' (aka 'unsigned long long') [-Wformat]
   30 |         TF_CODING_ERROR("Invalid interval: begin=%zu, end=%zu", begin, end);
      |                                                           ~~~          ^~~
      |                                                           %llu
/Users/dhruvgovil/Projects/usd/pxr/base/tf/diagnostic.h:307:42: note: expanded from macro 'TF_CODING_ERROR'
  307 |         TF_DIAGNOSTIC_CODING_ERROR_TYPE, __VA_ARGS__)
      |                                          ^~~~~~~~~~~
2 warnings generated.
/Users/dhruvgovil/Projects/usd/pxr/base/trace/wrapCollector.cpp:30:65: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'TraceEvent::TimeStamp' (aka 'unsigned long long') [-Wformat]
   30 |         TF_CODING_ERROR("Invalid interval: begin=%zu, end=%zu", begin, end);
      |                                                  ~~~            ^~~~~
      |                                                  %llu
/Users/dhruvgovil/Projects/usd/pxr/base/tf/diagnostic.h:307:42: note: expanded from macro 'TF_CODING_ERROR'
  307 |         TF_DIAGNOSTIC_CODING_ERROR_TYPE, __VA_ARGS__)
      |                                          ^~~~~~~~~~~
/Users/dhruvgovil/Projects/usd/pxr/base/trace/wrapCollector.cpp:30:72: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'TraceEvent::TimeStamp' (aka 'unsigned long long') [-Wformat]
   30 |         TF_CODING_ERROR("Invalid interval: begin=%zu, end=%zu", begin, end);
      |                                                           ~~~          ^~~
      |                                                           %llu
/Users/dhruvgovil/Projects/usd/pxr/base/tf/diagnostic.h:307:42: note: expanded from macro 'TF_CODING_ERROR'
  307 |         TF_DIAGNOSTIC_CODING_ERROR_TYPE, __VA_ARGS__)
      |                                          ^~~~~~~~~~~
2 warnings generated.

/Users/dhruvgovil/Projects/usd/pxr/imaging/hd/testenv/testHdSortedIdsPerf.cpp:388:37: warning: format specifies type 'ssize_t' (aka 'long') but the argument has type 'long long' [-Wformat]
  387 |                 "{'profile':'%s','metric':'time','value':%zd,'samples':1}\n",
      |                                                          ~~~
      |                                                          %lld
  388 |                 metricName.c_str(), ns);
      |                                     ^~
/Users/dhruvgovil/Projects/usd/pxr/imaging/hd/testenv/testHdSortedIdsPerf.cpp:389:53: warning: format specifies type 'ssize_t' (aka 'long') but the argument has type 'long long' [-Wformat]
  389 |         printf("%s : %zd ns\n", metricName.c_str(), ns);
      |                      ~~~                            ^~
      |                      %lld

/Users/dhruvgovil/Projects/usd/pxr/imaging/hd/testenv/testHdSortedIdsPerf.cpp:388:37: warning: format specifies type 'ssize_t' (aka 'long') but the argument has type 'long long' [-Wformat]
  387 |                 "{'profile':'%s','metric':'time','value':%zd,'samples':1}\n",
      |                                                          ~~~
      |                                                          %lld
  388 |                 metricName.c_str(), ns);
      |                                     ^~
/Users/dhruvgovil/Projects/usd/pxr/imaging/hd/testenv/testHdSortedIdsPerf.cpp:389:53: warning: format specifies type 'ssize_t' (aka 'long') but the argument has type 'long long' [-Wformat]
  389 |         printf("%s : %zd ns\n", metricName.c_str(), ns);
      |                      ~~~                            ^~
      |                      %lld
4 warnings generated.
jesschimein commented 1 day ago

Filed as internal issue #USD-10233