Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 119632 - gcc-3.4.5 - Incorrect value for errno for strtol() if success
Summary: gcc-3.4.5 - Incorrect value for errno for strtol() if success
Status: RESOLVED INVALID
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: High critical
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-19 18:47 UTC by Alexey Parshin
Modified: 2006-01-21 21:03 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexey Parshin 2006-01-19 18:47:47 UTC
The strtol() function doesn't set errno to 0 in case of successful convertion.
Currently, I'm using the following code to make it work:

errno = 0;
strtol(....);
if (errno) {
   /// report an error
}

gcc --version
gcc (GCC) 3.4.5 (Gentoo 3.4.5, ssp-3.4.5-1.0, pie-8.7.9)
Comment 1 SpanKY gentoo-dev 2006-01-20 04:03:05 UTC
that is often the case

errno has no valid meaning unless an error occured
Comment 2 Alexey Parshin 2006-01-20 16:43:37 UTC
Intersting. And 

1) why did it always work before in GCC?
2) why it works in all the other compilers (I'm doing cross-platform development here) - gcc, borland, msvc++, etc ..?
3) how I suppose to know if the conversion was ok? In my case, after the successful conversion the value of errno was 'file not found'.. The return value of that function can only reflect overflow/underflow.
4) the interesting part. If the prior call to strtol sets errno to EINVAL, and we call it again, successfully - but the errno is still EINVAL?

(In reply to comment #1)
> that is often the case
> 
> errno has no valid meaning unless an error occured
> 

Comment 3 SpanKY gentoo-dev 2006-01-21 21:03:58 UTC
read the manpage

The strtol() function returns the result of the conversion, unless the value would underflow or overflow. If an underflow occurs, strtol() returns LONG_MIN.  If an overflow occurs, strtol() returns LONG_MAX.