Skip to contentSkip to conversation

Define uintptr_t as long int to simplify printf() format strings

PATCH New Simon Glass 3 participants 6 messages Nov 4, 2011 – Nov 22, 2011 Library code

lore
Share & tools
lore
#0 lore raw

PATCH v3 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.

---
Changes in v3:
- Remove the #if logic since it doesn't really do anything

 include/compiler.h |   12 +++---------
 1 files changed, 3 insertions(+), 9 deletions(-)
include/compiler.h +3 -9
index 54999a7..0734ed4 100644
@@ -123,16 +123,10 @@ typedef unsigned int uint;
 #define __WORDSIZE	32
 #endif
 
-/* Types for `void *' pointers. */
-#if __WORDSIZE == 64
-typedef unsigned long int       uintptr_t;
-#elif __WORDSIZE == 32
-typedef unsigned int            uintptr_t;
-#else
-#error "__WORDSIZE has unexpected value"
-#endif
+/* Type for `void *' pointers. */
+typedef unsigned long int uintptr_t;
 
-#endif
+#endif /* USE_HOSTCC */
 
 /* compiler options */
 #define uninitialized_var(x)		x = x
Signature · 1 line
1.7.3.1
#1 lore raw

PATCH v3 2/3 Fix warnings in cmd_nvedit.c

This printf() string should be %ld now that uintptr_t is defined as long. Also fix a size_t error.

---

 common/cmd_nvedit.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
common/cmd_nvedit.c +2 -2
index 396a171..8895335 100644
@@ -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) {
Signature · 1 line
1.7.3.1
#2 lore raw

PATCH v3 2/3 Fix warnings in cmd_nvedit.c

Quoted 6 lines · Simon Glass

This printf() string should be %ld now that uintptr_t is defined as long. Also fix a size_t error.

---

Applied to u-boot-staging, sbabic at denx.de, thanks.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#3 lore raw

PATCH v3 3/3 sandbox: Fix warnings in hashtable.c

In reply to Simon Glass

This fixes a few printf() strings for size_t which are missing the 'z' modifier.

---
Changes in v2:
- Fix another warning in the same file

 lib/hashtable.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
lib/hashtable.c +4 -4
index 6895550..fca9d6e 100644
@@ -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: %zu, 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;
 	}
Signature · 1 line
1.7.3.1
#5 lore raw

PATCH v3 1/3 Define uintptr_t as long int to simplify printf() format strings

In reply to Simon Glass
Quoted 7 lines · Simon Glass

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.

---

Applied to u-boot-staging, sbabic at denx.de, thanks.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================