]> pd.if.org Git - pdclib/commitdiff
Handling end-of-string and unspecified width.
authorsolar <unknown>
Thu, 1 Oct 2009 05:46:26 +0000 (05:46 +0000)
committersolar <unknown>
Thu, 1 Oct 2009 05:46:26 +0000 (05:46 +0000)
functions/_PDCLIB/scan.c

index b6012611b707b290158d4c3585de5a271149790b..f41079bd78ee98908e98642e14011ff3ac21718a 100644 (file)
@@ -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;
             }
         }