Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler Warnings: Incorrect format specifiers #3336

Open
dgovil opened this issue Oct 2, 2024 · 4 comments
Open

Compiler Warnings: Incorrect format specifiers #3336

dgovil opened this issue Oct 2, 2024 · 4 comments
Labels
good first issue Indicates a good issue for first-time contributors help wanted Indicates an issue where help and/or a pull request from the community would be very welcome

Comments

@dgovil
Copy link
Contributor

dgovil commented Oct 2, 2024

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.
@dgovil dgovil added the good first issue Indicates a good issue for first-time contributors label Oct 2, 2024
@jesschimein
Copy link
Collaborator

Filed as internal issue #USD-10233

@pixar-oss pixar-oss added the help wanted Indicates an issue where help and/or a pull request from the community would be very welcome label Oct 24, 2024
@icathychen
Copy link

Hello, may I take this issue? thanks!

@dgovil
Copy link
Contributor Author

dgovil commented Nov 19, 2024

Yes, please go ahead and thanks in advance!

This was referenced Dec 6, 2024
@icathychen
Copy link

Hi, I've created a pull request for this issue. #3455

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Indicates a good issue for first-time contributors help wanted Indicates an issue where help and/or a pull request from the community would be very welcome
Projects
None yet
Development

No branches or pull requests

4 participants