Bug#584474: FTBFS: usbms.c:315: error: format ‘%02x’ expects type ‘unsigned int’
Source: grub2
Version: 1.98+20100602-1
Severity: serious
Tags: upstream patch
Justification: FTBFS
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
while investigated an unrelated bug, i noticed that the latest snapshot uploaded to debian fails with the following error:
gcc-4.4 -Idisk -I/home/seanius/grub2-1.98+20100602/disk -I/home/seanius/grub2-1.98+20100602/include -I. -I./include -Wall -W -ffreestanding -Os -DGRUB_MACHINE_EMU=1 -DMACHINE=X86_64_EMU -Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes -Wundef -Wstrict-prototypes -g -fno-dwarf2-cfi-asm -m64 -fno-stack-protector -mno-stack-arg-probe -Werror -DGRUB_TARGET_NO_MODULES=1 -DUSE_ASCII_FAILBACK=1 -DGRUB_FILE=\"disk/usbms.c\" -MD -c -o usbms_mod-disk_usbms.o /home/seanius/grub2-1.98+20100602/disk/usbms.c
cc1: warnings being treated as errors/home/seanius/grub2-1.98+20100602/disk/usbms.c: In function ‘grub_usbms_transfer’:/home/seanius/grub2-1.98+20100602/disk/usbms.c:315: error: format ‘%02x’ expects type ‘unsigned int’, but argument 5 has type ‘grub_size_t’ /home/seanius/grub2-1.98+20100602/disk/usbms.c:333: error: format ‘%02x’ expects type ‘unsigned int’, but argument 5 has type ‘grub_size_t’ make[1]: *** [usbms_mod-disk_usbms.o] Error 1
the two lines in question are both debug printf type statements. therefore, instead of doing something complicated to get the format string to match with the size of grub_size_t (which i'm guessing could vary based on the platform), i have created a patch that simply casts the parameter in question as unsigned to match the format string instead (which only shows two digits anyway).
sean
- -- System Information:
Debian Release: squeeze/sid
APT prefers unstable
APT policy: (500, 'unstable'), (500, 'testing'), (1, 'experimental')
Architecture: amd64 (x86_64)
Kernel: Linux 2.6.34-rc5minime-00783-gbad884d (SMP w/2 CPU cores)
Locale: LANG=en_US.utf8, LC_CTYPE=en_US.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
iD4DBQFMCAImynjLPm522B0RAsldAJjTMs+9qU0jot0h06FdvMFG8nQCAJ0f0c0X Fu2Hnjr1OrS/XiOazgU1bQ==
=+y8T
-----END PGP SIGNATURE-----
disk/usbms.c +2 -2
@@ -312,7 +312,7 @@ grub_usbms_transfer (struct grub_scsi *sgrub_dprintf ("usb" ,"buf:\n" );if (size <=64 )for (i=0 ; i<size; i++) -grub_dprintf ("usb" ,"0x%02x: 0x%02x\n" , i, buf[i]); +grub_dprintf ("usb" ,"0x%02x: 0x%02x\n" , (unsigned )i, buf[i]);else grub_dprintf ("usb" ,"Too much data for debug print...\n" ); }
@@ -330,7 +330,7 @@ grub_usbms_transfer (struct grub_scsi *s/* Debug print of sent data. */ if (size <=256 )for (i=0 ; i<size; i++) -grub_dprintf ("usb" ,"0x%02x: 0x%02x\n" , i, buf[i]); +grub_dprintf ("usb" ,"0x%02x: 0x%02x\n" , (unsigned )i, buf[i]);else grub_dprintf ("usb" ,"Too much data for debug print...\n" ); }
Quoted 10 lines · sean finney
while investigated an unrelated bug, i noticed that the latest snapshot uploaded to debian fails with the following error:
gcc-4.4 -Idisk -I/home/seanius/grub2-1.98+20100602/disk -I/home/seanius/grub2-1.98+20100602/include -I. -I./include -Wall -W -ffreestanding -Os -DGRUB_MACHINE_EMU=1 -DMACHINE=X86_64_EMU -Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes -Wundef -Wstrict-prototypes -g -fno-dwarf2-cfi-asm -m64 -fno-stack-protector -mno-stack-arg-probe -Werror -DGRUB_TARGET_NO_MODULES=1 -DUSE_ASCII_FAILBACK=1 -DGRUB_FILE=\"disk/usbms.c\" -MD -c -o usbms_mod-disk_usbms.o
/home/seanius/grub2-1.98+20100602/disk/usbms.c
cc1: warnings being treated as errors/home/seanius/grub2-1.98+20100602/disk/usbms.c: In function ‘grub_usbms_transfer’:/home/seanius/grub2-1.98+20100602/disk/usbms.c:315: error: format ‘%02x’ expects type ‘unsigned int’, but argument 5 has type ‘grub_size_t’/home/seanius/grub2-1.98+20100602/disk/usbms.c:333: error: format ‘%02x’ expects type ‘unsigned int’, but argument 5 has type ‘grub_size_t’ make[1]: *** [usbms_mod-disk_usbms.o] Error 1
Quoted 6 lines
the two lines in question are both debug printf type statements. therefore, instead of doing something complicated to get the format string to match with the size of
grub_size_t(which i'm guessing could vary based on the platform), i have created a patch that simply casts the parameter in question as unsigned to match the format string instead (which only shows two digits anyway).
As Vladimir pointed out on IRC: no, that's a minimum field width, not a precision. It shows *at least* two digits.
I think I'd prefer to add a grub_printf length modifier to print grub_size_t values. 'z' is standard for size_t, so it seems reasonable to use that, it can be done in very little code, and it saves on ugly and inaccurate casts. Vladimir, what do you think?
(If this is unacceptable for whatever reason, then the proper fix would be to cast to (unsigned long long) and to use %02llx - but I prefer having an accurate length modifier, really.)
2010-06-04 Colin Watson <[email protected]>
* kern/misc.c (grub_vsnprintf_real): Support 'z' length modifier, for grub_size_t.
* disk/usbms.c (grub_usbms_transfer): Use it.
=== modified file 'disk/usbms.c'
usbms.c +2 -2
@@ -312,7 +312,7 @@ grub_usbms_transfer (struct grub_scsi *sgrub_dprintf ("usb" ,"buf:\n" );if (size <=64 )for (i=0 ; i<size; i++) -grub_dprintf ("usb" ,"0x%02x: 0x%02x\n" , i, buf[i]); +grub_dprintf ("usb" ,"0x%02zx: 0x%02x\n" , i, buf[i]);else grub_dprintf ("usb" ,"Too much data for debug print...\n" ); }
@@ -330,7 +330,7 @@ grub_usbms_transfer (struct grub_scsi *s/* Debug print of sent data. */ if (size <=256 )for (i=0 ; i<size; i++) -grub_dprintf ("usb" ,"0x%02x: 0x%02x\n" , i, buf[i]); +grub_dprintf ("usb" ,"0x%02zx: 0x%02x\n" , i, buf[i]);else grub_dprintf ("usb" ,"Too much data for debug print...\n" ); }
=== modified file 'kern/misc.c'
misc.c +11 -0
@@ -688,6 +688,7 @@ grub_vsnprintf_real (char *str, grub_sizint n;int longfmt =0 ;int longlongfmt =0 ; +int sizetfmt =0 ;int unsig =0 ;if (*fmt && *fmt =='-' )
@@ -740,6 +741,11 @@ grub_vsnprintf_real (char *str, grub_siz c = *fmt++; } } +else if (c =='z' ) + { + sizetfmt =1 ; + c = *fmt++; + }switch (c) {
@@ -770,6 +776,11 @@ grub_vsnprintf_real (char *str, grub_sizlong l =va_arg (args, long);grub_lltoa (tmp, c, l); } +else if (sizetfmt) + { +grub_size_t sz =va_arg (args, grub_size_t); +grub_lltoa (tmp, c, sz); + }else if (unsig) {unsigned u =va_arg (args, unsigned);
Thanks,
Signature · 1 line
Colin Watson [[email protected]]
Quoted 19 lines · Colin Watson
Quoted 10 lines · sean finney
while investigated an unrelated bug, i noticed that the latest snapshot uploaded to debian fails with the following error:
gcc-4.4 -Idisk -I/home/seanius/grub2-1.98+20100602/disk -I/home/seanius/grub2-1.98+20100602/include -I. -I./include -Wall -W -ffreestanding -Os -DGRUB_MACHINE_EMU=1 -DMACHINE=X86_64_EMU -Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes -Wundef -Wstrict-prototypes -g -fno-dwarf2-cfi-asm -m64 -fno-stack-protector -mno-stack-arg-probe -Werror -DGRUB_TARGET_NO_MODULES=1 -DUSE_ASCII_FAILBACK=1 -DGRUB_FILE=\"disk/usbms.c\" -MD -c -o usbms_mod-disk_usbms.o
/home/seanius/grub2-1.98+20100602/disk/usbms.c
cc1: warnings being treated as errors/home/seanius/grub2-1.98+20100602/disk/usbms.c: In function ‘grub_usbms_transfer’:/home/seanius/grub2-1.98+20100602/disk/usbms.c:315: error: format ‘%02x’ expects type ‘unsigned int’, but argument 5 has type ‘grub_size_t’/home/seanius/grub2-1.98+20100602/disk/usbms.c:333: error: format ‘%02x’ expects type ‘unsigned int’, but argument 5 has type ‘grub_size_t’ make[1]: *** [usbms_mod-disk_usbms.o] Error 1Quoted 7 lines
the two lines in question are both debug printf type statements. therefore, instead of doing something complicated to get the format string to match with the size of
grub_size_t(which i'm guessing could vary based on the platform), i have created a patch that simply casts the parameter in question as unsigned to match the format string instead (which only shows two digits anyway).
Quoted 9 lines
As Vladimir pointed out on IRC: no, that's a minimum field width, not a precision. It shows *at least* two digits.
I think I'd prefer to add a
grub_printflength modifier to printgrub_size_tvalues. 'z' is standard forsize_t, so it seems reasonable to use that, it can be done in very little code, and it saves on ugly and inaccurate casts. Vladimir, what do you think?
grub_size_t is always of the same length as long. Perhaps we should define it as unsigned long, use "%lx" and get rid of useless difference on 32-bit and 64-bit platforms.
Are there any reasons not to do this way?
Alternatively %zx can be aliased to %lx in one code line.
Quoted 71 lines
(If this is unacceptable for whatever reason, then the proper fix would be to cast to (unsigned long long) and to use %02llx - but I prefer having an accurate length modifier, really.)
2010-06-04 Colin Watson <[email protected]>
*
kern/misc.c(grub_vsnprintf_real): Support 'z' length modifier, forgrub_size_t.
*disk/usbms.c(grub_usbms_transfer): Use it.=== modified file '
disk/usbms.c'usbms.c +2
-2@@ -312,7 +312,7 @@ grub_usbms_transfer (struct grub_scsi *sgrub_dprintf ("usb" ,"buf:\n" );if (size <=64 )for (i=0 ; i<size; i++) -grub_dprintf ("usb" ,"0x%02x: 0x%02x\n" , i, buf[i]); +grub_dprintf ("usb" ,"0x%02zx: 0x%02x\n" , i, buf[i]);else grub_dprintf ("usb" ,"Too much data for debug print...\n" ); }@@ -330,7 +330,7 @@ grub_usbms_transfer (struct grub_scsi *s/* Debug print of sent data. */ if (size <=256 )for (i=0 ; i<size; i++) -grub_dprintf ("usb" ,"0x%02x: 0x%02x\n" , i, buf[i]); +grub_dprintf ("usb" ,"0x%02zx: 0x%02x\n" , i, buf[i]);else grub_dprintf ("usb" ,"Too much data for debug print...\n" ); }=== modified file '
kern/misc.c'misc.c +11
-0@@ -688,6 +688,7 @@ grub_vsnprintf_real (char *str, grub_sizint n;int longfmt =0 ;int longlongfmt =0 ; +int sizetfmt =0 ;int unsig =0 ;if (*fmt && *fmt =='-' )@@ -740,6 +741,11 @@ grub_vsnprintf_real (char *str, grub_siz c = *fmt++; } } +else if (c =='z' ) + { + sizetfmt =1 ; + c = *fmt++; + }switch (c) {@@ -770,6 +776,11 @@ grub_vsnprintf_real (char *str, grub_sizlong l =va_arg (args, long);grub_lltoa (tmp, c, l); } +else if (sizetfmt) + { +grub_size_t sz =va_arg (args, grub_size_t); +grub_lltoa (tmp, c, sz); + }else if (unsig) {unsigned u =va_arg (args, unsigned);Thanks,
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 9 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 7 lines · Colin Watson
As Vladimir pointed out on IRC: no, that's a minimum field width, not a precision. It shows *at least* two digits.
I think I'd prefer to add a
grub_printflength modifier to printgrub_size_tvalues. 'z' is standard forsize_t, so it seems reasonable to use that, it can be done in very little code, and it saves on ugly and inaccurate casts. Vladimir, what do you think?
Quoted 4 lines
grub_size_tis always of the same length as long. Perhaps we should define it as unsigned long, use "%lx" and get rid of useless difference on 32-bit and 64-bit platforms.
Are there any reasons not to do this way?
Good point; I hadn't spotted that. Mostly clarity, I think. If it comes out as unsigned long anyway then it doesn't make any difference in the machine representation, but the different definitions do seem useful for clarity. If we change that (I had to read over it a few times to convince myself), then we should comment it very carefully. A comment near the #error if GRUB_CPU_SIZEOF_VOID_P != GRUB_CPU_SIZEOF_LONG to say that we'll need to change the grub_size_t definition if we ever support an architecture where void * isn't the same length as long would also be good, I think.
There is no assertion that GRUB_TARGET_SIZEOF_VOID_P == GRUB_TARGET_SIZEOF_LONG, although it's currently true for all targets. Should there be?
Quoted 1 line
Alternatively %zx can be aliased to %lx in one code line.
I do like being explicit about the length modifier but I understand that kern/misc.c needs to be as small as possible, so I'm not going to be precious about it. How about a compromise along the lines of C99's <inttypes.h> to reduce the probability of introducing errors when we add new targets? Following that (unfortunately ugly) pattern, we'd get something like:
#define PRIxGRUB_SIZE "lx"
If you think it's unlikely that grub_size_t will ever need to be anything other than unsigned long even on future targets, then maybe we don't need to worry about that.
Thanks,
Signature · 1 line
Colin Watson [[email protected]]
Quoted 17 lines · Colin Watson
Quoted 10 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 8 lines · Colin Watson
As Vladimir pointed out on IRC: no, that's a minimum field width, not a precision. It shows *at least* two digits.
I think I'd prefer to add a
grub_printflength modifier to printgrub_size_tvalues. 'z' is standard forsize_t, so it seems reasonable to use that, it can be done in very little code, and it saves on ugly and inaccurate casts. Vladimir, what do you think?Quoted 5 lines
grub_size_tis always of the same length as long. Perhaps we should define it as unsigned long, use "%lx" and get rid of useless difference on 32-bit and 64-bit platforms.
Are there any reasons not to do this way?
Quoted 4 lines
Good point; I hadn't spotted that. Mostly clarity, I think. If it comes out as unsigned long anyway then it doesn't make any difference in the machine representation, but the different definitions do seem useful for clarity.
Of course, I've never suggested an elimination of grub_size_t only doing like:
typedef unsigned long grub_size_t;
Quoted 7 lines
If we change that (I had to read over it a few times to convince myself), then we should comment it very carefully. A comment near the #error if
GRUB_CPU_SIZEOF_VOID_P!=GRUB_CPU_SIZEOF_LONGto say that we'll need to change thegrub_size_tdefinition if we ever support an architecture where void * isn't the same length as long would also be good, I think.
Ok. We can do the same for grub_addr_t too.
Quoted 5 lines
There is no assertion that
GRUB_TARGET_SIZEOF_VOID_P==GRUB_TARGET_SIZEOF_LONG, although it's currently true for all targets. Should there be?
It can be added but currently GRUB_CPU_SIZEOF_* changes between TARGET_* and HOST_* so if sizes mismatch either util or target part won't compile.
Quoted 11 lines
Quoted 2 lines
Alternatively %zx can be aliased to %lx in one code line.
I do like being explicit about the length modifier but I understand that
kern/misc.cneeds to be as small as possible, so I'm not going to be precious about it. How about a compromise along the lines of C99's <inttypes.h> to reduce the probability of introducing errors when we add new targets? Following that (unfortunately ugly) pattern, we'd get something like:#define PRIxGRUB_SIZE "lx"
It's a good idea. Since it will be something heavily used perhaps it's better to make an exception to usual GRUB style and shorten it somehow? But if we do e.g. PRIxG_SIZE we may end up with conflicts with other headers in utils
Quoted 5 lines
If you think it's unlikely that
grub_size_twill ever need to be anything other than unsigned long even on future targets, then maybe we don't need to worry about that.
Actualy it's not so much of a "target" as a "compiler-target" pair. Different compilers pick different machine-available sizes on same platform for the same type of int.
Quoted 3 lines
Thanks,
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko