@@ -254,7 +254,11 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status )
254254 break ;
255255 case 'c' :
256256 {
257- char * c = va_arg ( status -> arg , char * );
257+ char * c = NULL ;
258+ if ( ! status -> flags & E_suppressed )
259+ {
260+ c = va_arg ( status -> arg , char * );
261+ }
258262 /* for %c, default width is one */
259263 if ( status -> width == SIZE_MAX )
260264 {
@@ -264,13 +268,19 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status )
264268 while ( ( status -> current < status -> width ) &&
265269 ( ( rc = GET ( status ) ) != EOF ) )
266270 {
267- * (c ++ ) = rc ;
271+ if ( c != NULL )
272+ {
273+ * (c ++ ) = rc ;
274+ }
268275 value_parsed = 1 ;
269276 }
270277 /* width or input exhausted */
271278 if ( value_parsed )
272279 {
273- ++ status -> n ;
280+ if ( c != NULL )
281+ {
282+ ++ status -> n ;
283+ }
274284 return ++ spec ;
275285 }
276286 else
@@ -285,7 +295,11 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status )
285295 }
286296 case 's' :
287297 {
288- char * c = va_arg ( status -> arg , char * );
298+ char * c = NULL ;
299+ if ( ! status -> flags & E_suppressed )
300+ {
301+ c = va_arg ( status -> arg , char * );
302+ }
289303 while ( ( status -> current < status -> width ) &&
290304 ( ( rc = GET ( status ) ) != EOF ) )
291305 {
@@ -295,8 +309,11 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status )
295309 if ( value_parsed )
296310 {
297311 /* matching sequence terminated by whitespace */
298- * c = '\0' ;
299- ++ status -> n ;
312+ if ( c != NULL )
313+ {
314+ * c = '\0' ;
315+ ++ status -> n ;
316+ }
300317 return ++ spec ;
301318 }
302319 else
@@ -308,15 +325,21 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status )
308325 else
309326 {
310327 /* match */
328+ if ( c != NULL )
329+ {
330+ * (c ++ ) = rc ;
331+ }
311332 value_parsed = 1 ;
312- * (c ++ ) = rc ;
313333 }
314334 }
315335 /* width or input exhausted */
316336 if ( value_parsed )
317337 {
318- * c = '\0' ;
319- ++ status -> n ;
338+ if ( c != NULL )
339+ {
340+ * c = '\0' ;
341+ ++ status -> n ;
342+ }
320343 return ++ spec ;
321344 }
322345 else
@@ -333,7 +356,11 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status )
333356 {
334357 const char * endspec = spec ;
335358 int negative_scanlist = 0 ;
336- char * c ;
359+ char * c = NULL ;
360+ if ( ! status -> flags & E_suppressed )
361+ {
362+ c = va_arg ( status -> arg , char * );
363+ }
337364 if ( * (++ endspec ) == '^' )
338365 {
339366 negative_scanlist = 1 ;
@@ -346,7 +373,6 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status )
346373 ++ endspec ;
347374 } while ( * endspec != ']' );
348375 /* read according to scanlist, equiv. to %s above */
349- c = va_arg ( status -> arg , char * );
350376 while ( ( status -> current < status -> width ) &&
351377 ( ( rc = GET ( status ) ) != EOF ) )
352378 {
@@ -366,18 +392,25 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status )
366392 break ;
367393 }
368394 }
395+ if ( c != NULL )
396+ {
397+ * (c ++ ) = rc ;
398+ }
369399 value_parsed = 1 ;
370- * (c ++ ) = rc ;
371400 }
401+ /* width or input exhausted */
372402 if ( value_parsed )
373403 {
374- * c = '\0' ;
375- ++ status -> n ;
404+ if ( c != NULL )
405+ {
406+ * c = '\0' ;
407+ ++ status -> n ;
408+ }
376409 return ++ endspec ;
377410 }
378411 else
379412 {
380- if ( rc == EOF )
413+ if ( status -> n == 0 )
381414 {
382415 status -> n = -1 ;
383416 }
@@ -390,8 +423,11 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status )
390423 break ;
391424 case 'n' :
392425 {
393- int * val = va_arg ( status -> arg , int * );
394- * val = status -> i ;
426+ if ( ! status -> flags & E_suppressed )
427+ {
428+ int * val = va_arg ( status -> arg , int * );
429+ * val = status -> i ;
430+ }
395431 return ++ spec ;
396432 }
397433 default :
@@ -585,7 +621,7 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status )
585621 break ;
586622
587623 default :
588- puts ( "UNSUPPORTED SCANF FLAG COMBINATION" );
624+ fputs ( "UNSUPPORTED SCANF FLAG COMBINATIONi\n" , stdout );
589625 return NULL ; /* behaviour unspecified */
590626 }
591627 ++ (status -> n );
0 commit comments