From 2f13296a39de23e7ea4cdda37f13ff214147c6be Mon Sep 17 00:00:00 2001 From: Martin Baute Date: Fri, 8 Apr 2016 08:18:17 +0200 Subject: [PATCH] Clearing the Tyndur tests. --- functions/_PDCLIB/print.c | 55 ++++++++++++++++++++++++------------- functions/stdio/vfprintf.c | 2 +- functions/stdio/vfscanf.c | 2 +- functions/stdio/vsnprintf.c | 2 +- functions/stdio/vsscanf.c | 2 +- 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/functions/_PDCLIB/print.c b/functions/_PDCLIB/print.c index 3ddf11d..6db55e8 100644 --- a/functions/_PDCLIB/print.c +++ b/functions/_PDCLIB/print.c @@ -159,6 +159,12 @@ static void intformat( intmax_t value, struct _PDCLIB_status_t * status ) */ static void int2base( intmax_t value, struct _PDCLIB_status_t * status ) { + /* Special case: zero value, zero precision -- no output (but padding) */ + if ( status->current == 0 && value == 0 && status->prec == 0 ) + { + intformat( value, status ); + return; + } /* Registering the character being printed at the end of the function here already so it will be taken into account when the deepestmost recursion does the prefix / padding stuff. @@ -505,28 +511,39 @@ const char * _PDCLIB_print( const char * spec, struct _PDCLIB_status_t * status puts( "UNSUPPORTED PRINTF FLAG COMBINATION" ); return NULL; } - ++(status->current); - if ( ( value / status->base ) != 0 ) - { - /* Get value to "safe" levels re. uintmax_t. */ - int2base( (intmax_t)(value / status->base), status ); - } - else - { - intformat( (intmax_t)value, status ); - } - int digit = value % status->base; - if ( digit < 0 ) - { - digit *= -1; - } - if ( status->flags & E_lower ) + /* Special case: zero value, zero precision: No output, just padding */ + if ( value == 0 && status->prec == 0 ) { - PUT( _PDCLIB_digits[ digit ] ); + int2base( 0, status ); } else { - PUT( _PDCLIB_Xdigits[ digit ] ); + /* To make the call to int2base (using intmax_t) safe for + uintmax_t values > INTMAX_MAX, we basically to the first + "recursion" level of int2base right here. + */ + ++(status->current); + if ( ( value / status->base ) != 0 ) + { + int2base( (intmax_t)(value / status->base), status ); + } + else + { + intformat( (intmax_t)value, status ); + } + int digit = value % status->base; + if ( digit < 0 ) + { + digit *= -1; + } + if ( status->flags & E_lower ) + { + PUT( _PDCLIB_digits[ digit ] ); + } + else + { + PUT( _PDCLIB_Xdigits[ digit ] ); + } } } else @@ -596,7 +613,7 @@ static int testprintf( char * buffer, const char * format, ... ) status.current = 0; status.s = buffer; status.width = 0; - status.prec = 0; + status.prec = EOF; status.stream = NULL; va_start( status.arg, format ); memset( buffer, '\0', 100 ); diff --git a/functions/stdio/vfprintf.c b/functions/stdio/vfprintf.c index 9d53d18..6f31bbd 100644 --- a/functions/stdio/vfprintf.c +++ b/functions/stdio/vfprintf.c @@ -21,7 +21,7 @@ int vfprintf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, const char * _PDC status.current = 0; status.s = NULL; status.width = 0; - status.prec = 0; + status.prec = EOF; status.stream = stream; va_copy( status.arg, arg ); diff --git a/functions/stdio/vfscanf.c b/functions/stdio/vfscanf.c index a19f18e..d70f5d5 100644 --- a/functions/stdio/vfscanf.c +++ b/functions/stdio/vfscanf.c @@ -21,7 +21,7 @@ int vfscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict forma status.current = 0; status.s = NULL; status.width = 0; - status.prec = 0; + status.prec = EOF; status.stream = stream; va_copy( status.arg, arg ); diff --git a/functions/stdio/vsnprintf.c b/functions/stdio/vsnprintf.c index a46491d..e57e682 100644 --- a/functions/stdio/vsnprintf.c +++ b/functions/stdio/vsnprintf.c @@ -20,7 +20,7 @@ int vsnprintf( char * _PDCLIB_restrict s, size_t n, const char * _PDCLIB_restric status.current = 0; status.s = s; status.width = 0; - status.prec = 0; + status.prec = EOF; status.stream = NULL; va_copy( status.arg, arg ); diff --git a/functions/stdio/vsscanf.c b/functions/stdio/vsscanf.c index a9076d0..4998b68 100644 --- a/functions/stdio/vsscanf.c +++ b/functions/stdio/vsscanf.c @@ -21,7 +21,7 @@ int vsscanf( const char * _PDCLIB_restrict s, const char * _PDCLIB_restrict form status.current = 0; status.s = (char *) s; status.width = 0; - status.prec = 0; + status.prec = EOF; status.stream = NULL; va_copy( status.arg, arg ); -- 2.40.0