mailing list of musl libc
 help / color / mirror / code / Atom feed
* scanf requirements not met?
@ 2013-04-05  1:52 Rich Felker
  2013-04-20 16:51 ` Rich Felker
  0 siblings, 1 reply; 6+ messages in thread
From: Rich Felker @ 2013-04-05  1:52 UTC (permalink / raw)
  To: musl

Hi all,

In consideration of adding the 'm' modifier for scanf and looking at
how it's supposed to handle malloc failure, I believe the current
implementation may be getting some things wrong. Seeing that it
defined malloc failure as a "conversion error":

    If there is insufficient memory to allocate a buffer, the function
    shall set errno to [ENOMEM] and a conversion error shall result.

I noticed that this was not either of the "failures" defined for
scanf: input or matching. The text "conversion error" does not occur
elsewhere, but the ERRORS section does specify:

    If any error occurs, EOF shall be returned, and errno shall be set
    to indicate the error.

The current behavior in musl is to treat EILSEQ and IO errors from the
underlying stdio layer as input failures, but in light of the above,
this seems wrong/non-conforming. It looks to me like, even if a number
of conversions have already taken place successfully, scanf is
required to return EOF anyway if an error is encountered later. This
also makes the following text make more sense:

    If the function returns EOF, any memory successfully allocated for
    parameters using assignment-allocation character 'm' by this call
    shall be freed before the function returns.

I previously thought the only way the function could return EOF was
when no successful conversions had taken place, in which case there
would be nothing to free. But if EOF can happen even after successful
conversions, then it makes sense. (And it's also a pain to implement.)

Does this all sound right? I'll probably wait until after the release
to go working on it, and add 'm' at the same time, since scanf is ugly
and fragile and not something I want to break pending a release.

Rich


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-04-22 11:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-05  1:52 scanf requirements not met? Rich Felker
2013-04-20 16:51 ` Rich Felker
2013-04-22  3:17   ` Rob Landley
2013-04-22  5:36     ` Isaac Dunham
2013-04-22  5:54       ` Szabolcs Nagy
2013-04-22 11:42         ` LM

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).