This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug stdio/15929] scanf doesn't set errno to ERANGE for unsigned short overflows


https://sourceware.org/bugzilla/show_bug.cgi?id=15929

--- Comment #2 from Filipe GonÃalves <filipe at codinghighway dot com> ---
(In reply to Andreas Schwab from comment #1)
> POSIX does not specify ERANGE for fscanf.  The ERANGE error comes from
> strtoul which checks against ULONG_MAX (not UINT_MAX).  If you want to do
> range checking you have to do it yourself.

Well, the manpage contradicts itself, it mentions that ERANGE is used when "The
result of an integer conversion would exceed the size that can be stored in the
corresponding integer type.", but later on it says that the standards to which
it conforms to do not mention ERANGE. What do we have then?

If I call scanf, I can't do range checking, by the time it returns, how am I
supposed to know if there was an overflow?

If ERANGE is not mentioned in the standards and that serves as an excuse on why
scanf doesn't deal with it properly, then it might be better to remove that
from the "ERRORS" section, otherwise, we have an awkward situation here, where
it kind of works, but when it doesn't, it's not a bug because the standard
doesn't mention it.

But ok then, I'll just code my own function to read an unsigned short and
forget that scanf exists.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]