[LTP] [PATCH v2 1/2] lib/safe_macros: Add SAFE_STRTOF
zhaogongyi
zhaogongyi@huawei.com
Mon Dec 5 08:03:57 CET 2022
Hi Cyril,
>
> Hi!
> > According to man 3 strtof, it seems there are some cases like:
> >
> > 1. strtof return the converted value as normal 2. strtof return 0 when
> > no conversion is performed, and endptr == nptr: 'rval == 0'
>
> We can ignore this case since we check that the string was consumed later
> on. That's the:
>
> + if (endptr == str || (*endptr != '\0' && *endptr != '\n')) {
> + tst_brkm_(file, lineno, TBROK, cleanup_fn,
> + "Invalid value: '%s'", str);
> + return 0;
> + }
>
>
> > 3. strtof return HUGE_VAL or -HUGE_VAL when overflow: '(rval ==
> HUGE_VAL) || (rval == -HUGE_VAL)'
> > 4. strtof retrun 0 and set errno to ERANGE when underflow: 'errno ==
> ERANGE'
>
> My manual says that the value is no larger than DBL_MIN, FLT_MIN, or
> LDBL_MIN in this case. Either way I would avoid checking the returned
> value in the case errno was set.
I usually look for information here: https://pubs.opengroup.org/onlinepubs/9699919799/
>
> > For 2, it seems need to add checking of endptr when 'rval == 0' like:
> > (rval == 0 && !strcmp(endptr, nptr)
>
> Again, no need to check the actual return value, we can just check that the
> string was consumed, which we already do.
>
Thanks! I have resubmit the patch as your suggestion.
Regards,
Gongyi
More information about the ltp
mailing list