Skip to contentSkip to conversation

lib/vsprintf.c: Fix handling of %zd when using ssize_t

PATCH New Jason Gunthorpe 1 participant 1 message Nov 21, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/vsprintf.c: Fix handling of %zd when using ssize_t

Documentation/printk-formats.txt says to use %zd for a ssize_t argument and some drivers do. Unfortunately this prints a positive number for negative values eg:

tpm_tis 70030000.tpm_tis: tpm_transmit: tpm_send: error 4294967234

Add a case to va_args a ssize_t type if the interpretation should be signed.

Tested on PPC32.

---
 lib/vsprintf.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
lib/vsprintf.c +4 -1
index 39c99fe..41da074 100644
@@ -1485,7 +1485,10 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
 				num = va_arg(args, long);
 				break;
 			case FORMAT_TYPE_SIZE_T:
-				num = va_arg(args, size_t);
+				if (spec.flags & SIGN)
+					num = va_arg(args, ssize_t);
+				else
+					num = va_arg(args, size_t);
 				break;
 			case FORMAT_TYPE_PTRDIFF:
 				num = va_arg(args, ptrdiff_t);
Signature · 1 line
1.7.4.1