>> My best guess about it is that strtod() is actively broken on your
>> platform, and is recognizing the "infinity" input but returning an
>> incorrect endptr. I seem to recall that we've heard of such bugs
>> before. Can you check for any updates from Sun that might affect
>> strtod()?
Hmm, take a look at this:
http://tcl.apache.org/sources/tcl/compat/fixstrtod.c.html
So at least the Tcl guys are aware of an issue. It looks from this code
like they expect Solaris strtod to return an endptr one past the end of
the string. Which would explain the apparently random behavior, because
that would be uninitialized memory --- if it happened to contain a zero
then we'd not register a complaint, but otherwise we would.
So forget my previous proposed patch and try this one:
/* skip leading whitespace */
while (*num != '\0' && isspace((unsigned char) *num))
num++;
errno = 0;
val = strtod(num, &endptr);
+ if (endptr != num && endptr[-1] == 0)
+ endptr--;
/* did we not see anything that looks like a double? */
regards, tom lane