[U-Boot-Users] [PATCH] Fix printf errors.
Andrew Klossner
andrew at cesa.opbu.xerox.com
Wed Jul 2 16:17:40 CEST 2008
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 corrects the resulting compiler
warnings in several files. Some of these were bugs, e.g., "$d"
instead of "%d" and incorrect arguments in common/cmd_fdt.c. 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.
I can only compile for ppc architecture so have not tested much of the
source code for further warnings.
common/cmd_fdt.c
common/common/main.c
cpu/mpc85xx/traps.c
include/common.h
lib_ppc/bootm.c
net/tftp.c
---
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(-)
diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c
index 97b9dd7..d3b19dd 100644
--- a/common/cmd_fdt.c
+++ b/common/cmd_fdt.c
@@ -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;
diff --git a/common/main.c b/common/main.c
index 046da6f..79ad291 100644
--- a/common/main.c
+++ b/common/main.c
@@ -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)
diff --git a/cpu/mpc85xx/traps.c b/cpu/mpc85xx/traps.c
index fd36658..0eab694 100644
--- a/cpu/mpc85xx/traps.c
+++ b/cpu/mpc85xx/traps.c
@@ -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
}
diff --git a/include/common.h b/include/common.h
index fd5adb3..51c2be8 100644
--- a/include/common.h
+++ b/include/common.h
@@ -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);
diff --git a/lib_ppc/bootm.c b/lib_ppc/bootm.c
index 10a0b12..f92f7a8 100644
--- a/lib_ppc/bootm.c
+++ b/lib_ppc/bootm.c
@@ -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 at 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");
diff --git a/net/tftp.c b/net/tftp.c
index ea8fea2..84d83ca 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -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
--
1.5.5
More information about the U-Boot
mailing list