Bug 9696 - strtod() should not return EDOM
Summary: strtod() should not return EDOM
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: math (show other bugs)
Version: 2.8
: P2 normal
Target Milestone: ---
Assignee: Andreas Jaeger
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-30 12:12 UTC by Peter Eisentraut
Modified: 2014-07-02 07:30 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments
Fix (637 bytes, patch)
2011-07-05 12:24 UTC, Andreas Jaeger
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Eisentraut 2008-12-30 12:12:50 UTC
During testing of corner cases in our software, we have discovered 
that

strtod("1E-324", NULL)

sets errno = EDOM.  I think this is not correct.

POSIX says this:

"""
These functions shall fail if:
[ERANGE]
The value to be returned would cause overflow or underflow. 

These functions may fail if:
[EINVAL]
No conversion could be performed.
"""

EDOM isn't even mentioned here.  My test case is an underflow case, 
so ERANGE should be set.

Also note that the analogous overflow case strtod("1E+324", NULL) 
does set ERANGE.

For comparison, the BSD libc (Mac OS X) as well as HP-UX set ERANGE 
in both cases.

The section in the glibc documentation "20.5.4 Error Reporting by 
Mathematical Functions" also appears to predict an ERANGE result.

Bug #6776, while unrelated code, mentions a similar issue of EDOM/
ERANGE confusion.
Comment 1 Andreas Jaeger 2011-07-05 12:24:52 UTC
Created attachment 5833 [details]
Fix

Thanks, here's a fix.

2011-07-05  Andreas Jaeger  <aj@suse.de>

        [BZ#9696]
        * stdlib/strtod_l.c (round_and_return): Return ERANGE instead of
        EDOM.
        * stdlib/tst-strtod.c: Add testcase.
Comment 2 Ulrich Drepper 2011-07-07 00:59:56 UTC
I checked in a patch.