From: Florian Krohm Date: Mon, 29 Dec 2014 19:05:37 +0000 (+0000) Subject: Add type SizeT (moved here from valgrind's pub_tool_basics.h). X-Git-Tag: svn/VALGRIND_3_11_0^2~128 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1023d38870f74937be656bb0de71625b5b57f249;p=thirdparty%2Fvalgrind.git Add type SizeT (moved here from valgrind's pub_tool_basics.h). Enhance vprintf_wrk to print such values (%zu, %zx, %zX). git-svn-id: svn://svn.valgrind.org/vex/trunk@3046 --- diff --git a/VEX/priv/main_util.c b/VEX/priv/main_util.c index ce93ba516c..9edbe35f6b 100644 --- a/VEX/priv/main_util.c +++ b/VEX/priv/main_util.c @@ -377,7 +377,7 @@ UInt vprintf_wrk ( void(*sink)(HChar), while (0) const HChar* saved_format; - Bool longlong, ljustify; + Bool longlong, ljustify, is_sizet; HChar padchar; Int fwidth, nout, len1, len2, len3; HChar intbuf[100]; /* big enough for a 64-bit # in base 2 */ @@ -397,7 +397,7 @@ UInt vprintf_wrk ( void(*sink)(HChar), } saved_format = format; - longlong = False; + longlong = is_sizet = False; ljustify = False; padchar = ' '; fwidth = 0; @@ -424,8 +424,11 @@ UInt vprintf_wrk ( void(*sink)(HChar), format++; if (*format == 'l') { format++; - longlong = True; + longlong = True; } + } else if (*format == 'z') { + format++; + is_sizet = True; } switch (*format) { @@ -454,6 +457,7 @@ UInt vprintf_wrk ( void(*sink)(HChar), } case 'd': { Long l; + vassert(is_sizet == False); // %zd is obscure; we don't allow it if (longlong) { l = va_arg(ap, Long); } else { @@ -474,7 +478,9 @@ UInt vprintf_wrk ( void(*sink)(HChar), Int base = *format == 'u' ? 10 : 16; Bool hexcaps = True; /* *format == 'X'; */ ULong l; - if (longlong) { + if (is_sizet) { + l = (ULong)va_arg(ap, SizeT); + } else if (longlong) { l = va_arg(ap, ULong); } else { l = (ULong)va_arg(ap, UInt); diff --git a/VEX/pub/libvex_basictypes.h b/VEX/pub/libvex_basictypes.h index 8ebf5aebbd..09205bb3af 100644 --- a/VEX/pub/libvex_basictypes.h +++ b/VEX/pub/libvex_basictypes.h @@ -59,6 +59,12 @@ typedef signed int Int; typedef unsigned long long int ULong; typedef signed long long int Long; +/* Equivalent of C's size_t type. The type is unsigned and has this + storage requirement: + 32 bits on a 32-bit architecture + 64 bits on a 64-bit architecture. */ +typedef unsigned long SizeT; + /* Always 128 bits. */ typedef UInt U128[4];