Re: Crashing g_string_sprintf when printing invalid floats. gtk+-1.2.9 on Linux
- From: "Eric M. Monsler" <emonsler beamreachnetworks com>
- To: Allin Cottrell <cottrell wfu edu>
- Cc: "gtk-list gnome org" <gtk-list gnome org>
- Subject: Re: Crashing g_string_sprintf when printing invalid floats. gtk+-1.2.9 on Linux
- Date: Tue, 13 Aug 2002 12:46:03 -0700
Allin Cottrell wrote:
Isn't that undefined behavior, trying to access the wrong member of a
union?
Yes. I am using that to force a bad floating point value.
Here (gtk 2.0.6) it prints "0.00", but I don't see that it's
obliged to.
I feel it should not crash on any input.
I have a similar test case, which uses:
tmp_float = (float)strtod("6.0e-44",NULL);
g_string_sprintf(pGStr,"%6.2f\n",tmp_float);
and produces the same crash. In that case, a "%g\n" format string
returns something within precision distance of 6.0e-44. The compiler
(gcc 2.95) accepts that a float can be denormalized, and operates on it
in various ways, but the g_string_sprintf() function does not.
The above is completely legal way to produce the crash, and an
application could well convert a (very small) double to a float and then
later try to print the float in a limited precision output format. That
argues that the correct behavior is indeed "0.00", and nothing else.
I guess the alternative would be to print "nan", but I'd vote for "0.00"
instead.
Eric
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]