Closed mstemm closed 2 years ago
Hi Mark, thanks for discovering this!
I suppose you could fix all includes of inttypes.h in libs to ensure that __STDC_FORMAT_MACROS is defined, but I would think an easier solution would be to move the implementation of the methods into a version.c file and control the includes there.
Can't we define the symbol as a compiler flag instead? I mean, this way the symbol is globally visible and exported before anything else.
Describe the bug
version.h at commit c8af440082fd996ade25b2128167168db98710a5 is a bit fragile with respect to its use of __STDC_FORMAT_MACROS. If that preprocessor define is set before including intttypes.h, it allows adding formatting directives like PRIu32 to sprintf/printf/etc.
The problem is that STDC_FORMAT_MACROS must be defined before the first include of inttypes.h. If another header includes version.h but also includes inttypes.h before version.h without STDC_FORMAT_MACROS, the formatting directives won't be available.
I suppose you could fix all includes of inttypes.h in libs to ensure that __STDC_FORMAT_MACROS is defined, but I would think an easier solution would be to move the implementation of the methods into a version.c file and control the includes there.
How to reproduce it
I can't include the full build log, since this is a custom use of libs, but I do get this error:
If I add __STDC_FORMAT_MACROS to the include of inttypes.h in userspace/libscap/plugin_info.h and userspace/libscap/uthash.h, I can build without this error.
Expected behaviour
Screenshots
Environment
Additional context