From f71f6eb494add94903f9c721927e96a3cb552aa0 Mon Sep 17 00:00:00 2001 From: solar Date: Thu, 1 Oct 2009 05:46:26 +0000 Subject: [PATCH] Handling end-of-string and unspecified width. --- functions/_PDCLIB/scan.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/functions/_PDCLIB/scan.c b/functions/_PDCLIB/scan.c index b601261..f41079b 100644 --- a/functions/_PDCLIB/scan.c +++ b/functions/_PDCLIB/scan.c @@ -47,7 +47,7 @@ static int GET( struct _PDCLIB_status_t * status ) } else { - return *((status->s)++); + return ( *status->s == '\0' ) ? EOF : *((status->s)++); } } @@ -106,7 +106,12 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ) strtol() will return zero. In both cases, endptr will point to the rest of the conversion specifier - just what we need. */ + char const * prev_spec = spec; status->width = (int)strtol( spec, (char**)&spec, 10 ); + if ( spec == prev_spec ) + { + status->width = SIZE_MAX; + } /* Optional length modifier We step one character ahead in any case, and step back only if we find @@ -216,6 +221,7 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ) } else { + /* FIXME: Need two kinds of "no match" here: zero width, and input error */ return NULL; } } -- 2.40.0