--- Begin Message ---
Package: gcc-4.4-base
Version: 4.4.4-7
Severity: critical
Tags: squeeze
Justification: causes serious data loss
When using one of the printf functions, guint64 variables cause the following
value to be incorrectly displyed.
The following code illustrates this:
#include <stdio.h>
#include <glib.h>
int main( argv, argc ) {
guint8 g1, g2;
guint64 g3, g4;
char *TS;
TS = "This is a test";
g1 = 1;
g2 = 2;
g3 = 3;
g4 = 4;
printf("g1 %u, g2 %u, g3 %u, g4 %u\n", g1, g2, g3, g4);
printf("g1 %u, g3 %u, g2 %u, g4 %u\n", g1, g3, g2, g4);
printf("g3 %u, TS %s\n", g3, TS);
printf("g1 %u\n", g1);
printf("g2 %u\n", g2);
printf("g3 %u\n", g3);
printf("g4 %u\n", g4);
printf("TS %s\n", TS);
return;
}
generates:
g1 1, g2 2, g3 3, g4 0
g1 1, g3 3, g2 0, g4 2
g3 3, TS (null)
g1 1
g2 2
g3 3
g4 4
TS This is a test
Note that output line 1, g4 outputs as 0, line2 g2 outputs as 0, and line 3
shows the string as NULL.
-- System Information:
Debian Release: squeeze/sid
APT prefers testing
APT policy: (990, 'testing'), (600, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.6.32-5-686 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
-- no debconf information
--- End Message ---
--- Begin Message ---
On 2010/08/07 01:16, Alex Lindberg <alindber@yahoo.com> wrote:
> When using one of the printf functions, guint64 variables cause the following
> value to be incorrectly displyed.
[...]
> guint64 g3, g4;
> char *TS;
> TS = "This is a test";
> g3 = 3;
> printf("g3 %u, TS %s\n", g3, TS);
> g3 3, TS (null)
> Note that output line 1, g4 outputs as 0, line2 g2 outputs as 0, and line 3
> shows the string as NULL.
The output does not meet your expectations, because your code is
broken.
"%u" expects an "unsigned int" (probably 32 bits on your platform),
while you attempt to pass "guint64" (64 bits). The result is
undefined.
You need to use G_GUINT64_FORMAT to format a guint64, see:
http://library.gnome.org/devel/glib/unstable/glib-Miscellaneous-Macros.html#G-GUINT64-FORMAT:CAPS
Max
--- End Message ---