Fix printf errors.
PATCH 1/1 Fix printf errors.
The compiler will help find mismatches between printf formats and arguments if you let it. This patch adds the necessary attributes to declarations in include/common.h, then begins to correct the resulting compiler warnings. Some of these were bugs, e.g., "$d" instead of "%d" and incorrect arguments. Others were just annoying, like int-long mismatches on a system where both are 32 bits. It's worth fixing the annoying errors to catch the real ones.
--- common/cmd_fdt.c | 8 ++++---- common/main.c | 2 +- cpu/mpc85xx/traps.c | 8 ++++---- include/common.h | 15 ++++++++++----- lib_ppc/bootm.c | 8 ++++---- net/tftp.c | 2 +- 6 files changed, 24 insertions(+), 19 deletions(-)
common/cmd_fdt.c +4 -4
@@ -451,14 +451,14 @@ static int fdt_valid(void)if (err == -FDT_ERR_BADVERSION ) {if (fdt_version (working_fdt) <FDT_FIRST_SUPPORTED_VERSION ) { -printf (" - too old, fdt $d < %d" , +printf (" - too old, fdt %d < %d" ,fdt_version (working_fdt),FDT_FIRST_SUPPORTED_VERSION ); working_fdt =NULL ; }if (fdt_last_comp_version (working_fdt) >FDT_LAST_SUPPORTED_VERSION ) { -printf (" - too new, fdt $d > %d" , +printf (" - too new, fdt %d > %d" ,fdt_version (working_fdt),FDT_LAST_SUPPORTED_VERSION ); working_fdt =NULL ;
@@ -546,7 +546,7 @@ static int fdt_parse_prop(char **newval, int count, char *data, int *len) newp = newval[++stridx]; }if (*newp !=']' ) { -printf ("Unexpected character '%c'\n" , *newval); +printf ("Unexpected character '%c'\n" , *newp);return 1 ; } }else {
@@ -763,7 +763,7 @@ static int fdt_print(const char *pathp, char *prop, int depth) }break ;case FDT_NOP : -printf ("/* NOP */\n" , &tabs[MAX_LEVEL - level]); +printf ("%s/* NOP */\n" , &tabs[MAX_LEVEL - level]);break ;case FDT_END :return 1 ;
common/main.c +1 -1
@@ -509,7 +509,7 @@ void reset_cmd_timeout(void)*/ #define putnstr (str,n) do { \ - printf ("%.*s", n, str); \ + printf ("%.*s", (int)n, str); \ } while (0)#define CTL_CH (c) ((c) - 'a' + 1)
cpu/mpc85xx/traps.c +4 -4
@@ -216,10 +216,10 @@ MachineCheckException(struct pt_regs *regs)if (machinecheck_count >1 ) { regs->nip +=4 ;/* skip offending instruction */ -printf ("Skipping current instr, Returning to 0x%08x\n" , +printf ("Skipping current instr, Returning to 0x%08lx\n" , regs->nip); }else { -printf ("Returning back to 0x%08x\n" ,regs->nip); +printf ("Returning back to 0x%08lx\n" ,regs->nip); } }
@@ -302,7 +302,7 @@ ExtIntException(struct pt_regs *regs)printf ("External Interrupt Exception at PC: %lx, SR: %lx, vector=%lx" , regs->nip, regs->msr, regs->trap); vect = pic->iack0; -printf (" irq IACK0@%05x=%d\n" ,&pic->iack0,vect); +printf (" irq IACK0@%05x=%d\n" ,(int )&pic->iack0,vect);show_regs (regs);print_backtrace ((unsigned long *)regs->gpr[1 ]); machinecheck_count++;
@@ -310,7 +310,7 @@ ExtIntException(struct pt_regs *regs)printf ("Returning back to 0x%08x\n" ,regs->nip);#else regs->nip +=4 ;/* skip offending instruction */ -printf ("Skipping current instr, Returning to 0x%08x\n" ,regs->nip); +printf ("Skipping current instr, Returning to 0x%08lx\n" ,regs->nip);#endif }
include/common.h +10 -5
@@ -607,8 +607,10 @@ ulong simple_strtoul(const char *cp,char **endp,unsigned int base);unsigned long long simple_strtoull (const char *cp,char **endp,unsigned int base);#endif long simple_strtol (const char *cp,char **endp,unsigned int base); -void panic (const char *fmt, ...); -int sprintf (char * buf,const char *fmt, ...); +void panic (const char *fmt, ...) + __attribute__ ((format (__printf__,1 ,2 ))); +int sprintf (char * buf,const char *fmt, ...) + __attribute__ ((format (__printf__,2 ,3 )));int vsprintf (char *buf,const char *fmt,va_list args);/* lib_generic/crc32.c */
@@ -630,7 +632,8 @@ int disable_ctrlc (int); /* 1 to disable, 0 to enable Control-C detect */*/ /* serial stuff */ -void serial_printf (const char *fmt, ...); +void serial_printf (const char *fmt, ...) + __attribute__ ((format (__printf__,1 ,2 )));/* stdin */ int getc (void );
@@ -639,7 +642,8 @@ int tstc(void);/* stdout */ void putc (const char c);void puts (const char *s); -void printf (const char *fmt, ...); +void printf (const char *fmt, ...) + __attribute__ ((format (__printf__,1 ,2 )));void vprintf (const char *fmt,va_list args);/* stderr */
@@ -656,7 +660,8 @@ void vprintf(const char *fmt, va_list args);#define stderr 2#define MAX_FILES 3 -void fprintf (int file,const char *fmt, ...); +void fprintf (int file,const char *fmt, ...) + __attribute__ ((format (__printf__,2 ,3 )));void fputs (int file,const char *s);void fputc (int file,const char c);int ftstc (int file);
lib_ppc/bootm.c +4 -4
@@ -101,7 +101,7 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],if (size < bootm_size) {ulong base = bootmap_base + size; -printf ("WARNING: adjusting available memory to %x\n" , size); +printf ("WARNING: adjusting available memory to %lx\n" , size);lmb_reserve (lmb, base, bootm_size - size); }
@@ -630,7 +630,7 @@ static int boot_get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],*/ fdt_blob = (char *)fdt_addr;debug ("* fdt: raw FDT blob\n" ); -printf ("## Flattened Device Tree blob at %08lx\n" , fdt_blob); +printf ("## Flattened Device Tree blob at %08lx\n" , (long )fdt_blob); }break ;default :
@@ -638,7 +638,7 @@ static int boot_get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], goto error; } -printf (" Booting using the fdt blob at 0x%x\n" , fdt_blob); +printf (" Booting using the fdt blob@0x%x\n" , (int )fdt_blob); }else if (images->legacy_hdr_valid &&image_check_type (&images->legacy_hdr_os_copy,IH_TYPE_MULTI )) {
@@ -657,7 +657,7 @@ static int boot_get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],if (fdt_len) { fdt_blob = (char *)fdt_data; -printf (" Booting using the fdt at 0x%x\n" , fdt_blob); +printf (" Booting using the fdt at 0x%x\n" , (int )fdt_blob);if (fdt_check_header (fdt_blob) !=0 ) {fdt_error ("image is not a fdt" );
net/tftp.c +1 -1
@@ -178,7 +178,7 @@ TftpSend (void) pkt +=5 /*strlen("octet")*/ +1 ;strcpy ((char *)pkt,"timeout" ); pkt +=7 /*strlen("timeout")*/ +1 ; -sprintf ((char *)pkt,"%d" ,TIMEOUT ); +sprintf ((char *)pkt,"%lu" ,TIMEOUT );#ifdef ET_DEBUG printf ("send option \"timeout %s\"\n" , (char *)pkt);#endif
Signature · 1 line
1.5.5
Wolfgang Denk
AppliedPATCH 1/1 Fix printf errors.
Quoted 9 lines · In message <[email protected]> you wrote:
The compiler will help find mismatches between printf formats and arguments if you let it. This patch adds the necessary attributes to declarations in
include/common.h, then begins to correct the resulting compiler warnings. Some of these were bugs, e.g., "$d" instead of "%d" and incorrect arguments. Others were just annoying, like int-long mismatches on a system where both are 32 bits. It's worth fixing the annoying errors to catch the real ones.Signed-off-by Andrew Klossner <[email protected]>
Quoted 8 lines
--- common/cmd_fdt.c | 8 ++++---- common/main.c | 2 +- cpu/mpc85xx/traps.c | 8 ++++---- include/common.h | 15 ++++++++++----- lib_ppc/bootm.c | 8 ++++---- net/tftp.c | 2 +- 6 files changed, 24 insertions(+), 19 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de The only way you could make a happy marriage is by cuttin' their heads off as soon as they say `I do', yes? You can't make happi- ness... - Terry Pratchett, _Witches Abroad_