Re: Crashing g_string_sprintf when printing invalid floats. gtk+-1.2.9 on Linux
- From: Chris Wareham <chris wareham iosystems co uk>
- To: "Eric M. Monsler" <emonsler beamreachnetworks com>
- Cc: Allin Cottrell <cottrell wfu edu>, "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: Wed, 14 Aug 2002 17:25:22 +0100
Eric M. Monsler wrote:
Inspecting errno when?
>
tmp_float = (float)strtod("6.0e-44",NULL);
/* inspect errno and tmp_float here - see strtod(3) */
if(errno == ERANGE) {
g_print("bad argument to strtod()\n");
exit(1);
} else if(tmp_float == FLT_MIN || tmp_float == FLT_MAX) {
g_print("float out of range\n");
exit(1);
}
g_string_sprintf(pGStr,"%6.2f\n",tmp_float);
Even better would be to skip the cast, make tmp_float
into tmp_double, and just check errno. This is because
FLT_MIN and FLT_MAX may not be portable beyond machines
with gcc on them.
Chris
--
chris wareham iosystems co uk (work)
cwareham btinternet com (home)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]