Closed dankamongmen closed 3 years ago
Re: Don't use bare %x for uint64_t. Cast to uintmax_t and use %jx.
Casting to uintmax_t isn't a better solution since it's 32 bits on 32-bit platforms. PRIu64 macro is the only valid portable way.
long long unsigned int
and "%llx" will work as well on all supported platform but it's ugly as well
Re: Don't use bare %x for uint64_t. Cast to uintmax_t and use %jx. Casting to uintmax_t isn't a better solution since it's 32 bits on 32-bit platforms. PRIu64 macro is the only valid portable way.
long long unsigned int
and "%llx" will work as well on all supported platform but it's ugly as well
I disagree. uintmax_t is defined to be "the largest supported integer type". Furthermore, the maximum value of uintmax_t is UINTMAX_MAX, which is guaranteed to be 2^64-1 or more by the standard.
http://www.cplusplus.com/reference/cstdint/
or straight from the C11 Standard:
7.20.2.5 Limits of greatest-width integer types
1
— minimum value of greatest-width signed integer type
−(2 63 − 1)
INTMAX_MIN
— maximum value of greatest-width signed integer type
2 63 − 1
INTMAX_MAX
— maximum value of greatest-width unsigned integer type
UINTMAX_MAX 2 64 − 1
I've attached the relevant pages.
Why can't we just use PRIu64
which is the most straightforward way?
Why can't we just use
PRIu64
which is the most straightforward way?
We can certainly do that. Would you like me to make the change and rebase?
Thanks. That would be appreciated.
The merge brought in a different solution anyway, so it's down to just the string fix.
strncpy() does not terminate the copied string if there is insufficient room. Since you were using strncpy() with the full size of the target buffer, this could lead to an unterminated string, and undefined behavior later (most likely, the strstr() would see problems).
Don't use bare %x for uint64_t. Cast to uintmax_t and use %jx.