GNOME Bugzilla – Bug 693347
Unsigned 64-bit numbers are printed wrongly when compiled with enable_included_printf
Last modified: 2017-11-16 11:00:24 UTC
Created attachment 235429 [details] [review] Patch file to fix the issue The function print_long_long always prints a long long number as signed (when conversion is "u", e.g. %llu in printf). So printing a number with the MSB set results in a negative output. E.g.: g_snprintf(buf, sizeof(buf), "%llu", 0xffffffffffffffffLL); will print "-1" (instead of 18446744073709551615). The problem seems to be, that the function always checks whether the number is negative, unless the conversion is o,x or X. default: base = 10; digits = lower; negative = (long long)number < 0; if (negative) number = -((long long)number); break; Adding a special case for 'u' would of course fix this (I think): case 'u': base = 10; digits = lower; negative = FALSE; break; I noticed this in glib 2.22.5 but it looks like this is still the same in the latest version? Of course this function is only used when glib is compiled with --enable-included-printf or the system does not provide a proper printf function itself.
This was fixed in bug #743936. *** This bug has been marked as a duplicate of bug 743936 ***