Re: Crashing g_string_sprintf when printing invalid floats. gtk+-1.2.9 on Linux



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]