After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 693347 - Unsigned 64-bit numbers are printed wrongly when compiled with enable_included_printf
Unsigned 64-bit numbers are printed wrongly when compiled with enable_include...
Status: RESOLVED DUPLICATE of bug 743936
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2013-02-07 17:21 UTC by Henry Margies
Modified: 2017-11-16 11:00 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch file to fix the issue (364 bytes, patch)
2013-02-07 17:21 UTC, Henry Margies
none Details | Review

Description Henry Margies 2013-02-07 17:21:26 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.
Comment 1 Philip Withnall 2017-11-16 11:00:24 UTC
This was fixed in bug #743936.

*** This bug has been marked as a duplicate of bug 743936 ***