sscanf() problems

Howland, Craig D howland@LGSInnovations.com
Tue Dec 2 22:22:00 GMT 2014


Jeff:

This sounds plausible, but then is also a bug: the SCN*8 defines in inttypes.h should not be defined when _WANT_IO_C99_FORMATS is not. This would provide a compilation error for the given test case. A #warning in inttypes.h might be appropriate.  (The C99 standard does explicitly call for the corresponding macros to not be defined if fscanf does not have a suitable length modifier for the type.)

For that matter, however, inttypes.h was added for C99, so an argument could be made that the entire file really should not be used if _WANT_IO_C99_FORMATS has not been defined. In which case inttypes.h should have a #error.
 
So, for example something along these lines:

Case 1, altered inttypes.h
#if !defined(_WANT_IO_C99_FORMATS)
   #warning "inttypes.h is not entirely safe to use when _WANT_IO_C99_FORMATS is not defined"
 #else
  // define the SCN*8 stuff
#endif
 
or

Case 2, no inttypes.h
#if !defined(_WANT_IO_C99_FORMATS)
  #error "inttypes.h must not be used when not full C99"
#endif

Thoughts on which approach is better? The first choice is major approach, for either no or altered inttypes.h. If altered, there's a question as to having a #warning or not. The warning would be spurious for people not using SCN*8.  People using SCN*8 will find out when compilation fails with or without a #warning, but the #warning would give them an immediate clue as to why.
 
Craig
________________________________________
From: newlib-owner@sourceware.org <newlib-owner@sourceware.org> on behalf of Jeff Johnston <jjohnstn@redhat.com>
Sent: Tuesday, December 2, 2014 3:28 PM
To: Steffen Wolfer
Cc: newlib@sourceware.org
Subject: Re: sscanf() problems

I believe I know what is happening.

The SCNu8 macro expands to be hhu

The vfscanf.c code only supports hh if the flag _WANT_IO_C99_FORMATS is set
to true.  By default it is false in newlib/configure.host and for a few select
platforms, it is set to true.

If you did not configure your library with --enable-newlib-io-c99-formats, then
it is false as arm doesn't set it to true.

...

-- Jeff J.

----- Original Message -----
> From: "Steffen Wolfer" <wolfer@weiss-robotics.de>
> To: newlib@sourceware.org
> Sent: Tuesday, December 2, 2014 6:21:20 AM
> Subject: sscanf() problems
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Dear all,
>
> I'm having the following, interesting problem using Newlib's sscanf().
> ...
>
>
> Thanks,
> Steffen



More information about the Newlib mailing list