[U-Boot] [PATCH 1/3] Define uintptr_t as long int to simplify printf() format strings

If uintptr_t can be either an unsigned int or an unsigned long int, it is tricky to use it in a printf() format string. This changes it to unsigned long int consistently. This should do the right thing on both 32-bit and 64-bit architectures.
Signed-off-by: Simon Glass sjg@chromium.org --- include/compiler.h | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/include/compiler.h b/include/compiler.h index 54999a7..17f4e93 100644 --- a/include/compiler.h +++ b/include/compiler.h @@ -124,10 +124,8 @@ typedef unsigned int uint; #endif
/* Types for `void *' pointers. */ -#if __WORDSIZE == 64 +#if __WORDSIZE == 64 || __WORDSIZE == 32 typedef unsigned long int uintptr_t; -#elif __WORDSIZE == 32 -typedef unsigned int uintptr_t; #else #error "__WORDSIZE has unexpected value" #endif

This printf() string should be %ld now that uintptr_t is defined as long. Also fix a size_t error.
Signed-off-by: Simon Glass sjg@chromium.org --- common/cmd_nvedit.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 396a171..8895335 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -405,7 +405,7 @@ int setenv_addr(const char *varname, const void *addr) { char str[17];
- sprintf(str, "%x", (uintptr_t)addr); + sprintf(str, "%lx", (uintptr_t)addr); return setenv(varname, str); }
@@ -862,7 +862,7 @@ static int do_env_import(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv " - truncated\n", MAX_ENV_SIZE); } ++size; - printf("## Info: input data size = %zd = 0x%zX\n", size, size); + printf("## Info: input data size = %zu = 0x%zX\n", size, size); }
if (chk) {

Acked-by: Mike Frysinger vapier@gentoo.org -mike

This fixes a few printf() strings for size_t which are missing the 'z' modifier.
Signed-off-by: Simon Glass sjg@chromium.org --- lib/hashtable.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/hashtable.c b/lib/hashtable.c index 6895550..a157cfa 100644 --- a/lib/hashtable.c +++ b/lib/hashtable.c @@ -491,8 +491,8 @@ ssize_t hexport_r(struct hsearch_data *htab, const char sep, return (-1); }
- debug("EXPORT table = %p, htab.size = %d, htab.filled = %d, size = %d\n", - htab, htab->size, htab->filled, size); + debug("EXPORT table = %p, htab.size = %d, htab.filled = %d, " + "size = %zu\n", htab, htab->size, htab->filled, size); /* * Pass 1: * search used entries, @@ -539,7 +539,7 @@ ssize_t hexport_r(struct hsearch_data *htab, const char sep, /* Check if the user supplied buffer size is sufficient */ if (size) { if (size < totlen + 1) { /* provided buffer too small */ - debug("### buffer too small: %d, but need %d\n", + debug("### buffer too small: %zd, but need %zu\n", size, totlen + 1); __set_errno(ENOMEM); return (-1); @@ -640,7 +640,7 @@ int himport_r(struct hsearch_data *htab,
/* we allocate new space to make sure we can write to the array */ if ((data = malloc(size)) == NULL) { - debug("himport_r: can't malloc %d bytes\n", size); + debug("himport_r: can't malloc %zu bytes\n", size); __set_errno(ENOMEM); return 0; }

Acked-by: Mike Frysinger vapier@gentoo.org -mike

On Thursday 03 November 2011 21:08:54 Simon Glass wrote:
--- a/include/compiler.h +++ b/include/compiler.h
/* Types for `void *' pointers. */ -#if __WORDSIZE == 64 +#if __WORDSIZE == 64 || __WORDSIZE == 32 typedef unsigned long int uintptr_t; -#elif __WORDSIZE == 32 -typedef unsigned int uintptr_t; #else #error "__WORDSIZE has unexpected value" #endif
i'd just delete the #if logic altogether considering we set up the values a few lines above -mike

On Thu, Nov 3, 2011 at 7:01 PM, Mike Frysinger vapier@gentoo.org wrote:
On Thursday 03 November 2011 21:08:54 Simon Glass wrote:
--- a/include/compiler.h +++ b/include/compiler.h
/* Types for `void *' pointers. */ -#if __WORDSIZE == 64 +#if __WORDSIZE == 64 || __WORDSIZE == 32 typedef unsigned long int uintptr_t; -#elif __WORDSIZE == 32 -typedef unsigned int uintptr_t; #else #error "__WORDSIZE has unexpected value" #endif
i'd just delete the #if logic altogether considering we set up the values a few lines above -mike
OK will do in v3 - Simon
participants (2)
-
Mike Frysinger
-
Simon Glass