|
From: Lutz M. <lut...@gm...> - 2008-05-20 01:33:05
|
On Monday 19 May 2008 17:46:08 Ethan Merritt wrote:
> What compiler and glibc versions are you using?
> What hardware? You probably said before, but I've forgotten.
gcc 4.2.1 on x86-64, glibc 2.6.1 release 18.3 (openSUSE 10.3 packages)
> Does the man page for strtol on your system claim that it will
> set errno on overflow?
I think so:
If the string has valid syntax for an integer but the value is not
representable because of overflow, `strtol' returns either
`LONG_MAX' or `LONG_MIN' (*note Range of Type::), as appropriate
for the sign of the value. It also sets `errno' to `ERANGE' to
indicate there was overflow.
> I assume that you also get something else for the simpler test case:
>
> gnuplot> t = 313136844993
> ^
> warning: integer overflow; changing to floating point
> gnuplot> print t
> 313136844993.0
This is what I get:
gnuplot> t = 313136844993
gnuplot> print t
-395767615
I think the reason for this behavior is that the call to strtol does not
generate an error, since the argument is within the range of a long
integer, but then there is an implicit conversion to the smaller int type:
token[t_num].l_val.v.int_val = strtol(str, &endptr, 0);
If I remember correctly, leading bits are simply truncated in a long->int
conversion, and errno is not set.
Hope this helps,
Lutz
|