From: zhaogongyi via ltp <ltp@lists.linux.it>
To: Cyril Hrubis <chrubis@suse.cz>
Cc: "ltp@lists.linux.it" <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH v2 1/2] lib/safe_macros: Add SAFE_STRTOF
Date: Mon, 5 Dec 2022 07:03:57 +0000 [thread overview]
Message-ID: <ee6ea2b055eb486a851b932a3d7ae92b@huawei.com> (raw)
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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2022-12-05 7:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-05 7:03 zhaogongyi via ltp [this message]
-- strict thread matches above, loose matches on Subject: below --
2022-12-02 2:54 [LTP] [PATCH v2 1/2] lib/safe_macros: Add SAFE_STRTOF zhaogongyi via ltp
2022-12-02 2:34 zhaogongyi via ltp
2022-12-02 10:37 ` Cyril Hrubis
2022-12-01 2:51 [LTP] [PATCH v2 0/2] Add handling of abnormal input for parse_opts() Zhao Gongyi via ltp
2022-12-01 2:51 ` [LTP] [PATCH v2 1/2] lib/safe_macros: Add SAFE_STRTOF Zhao Gongyi via ltp
2022-12-01 13:42 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ee6ea2b055eb486a851b932a3d7ae92b@huawei.com \
--to=ltp@lists.linux.it \
--cc=chrubis@suse.cz \
--cc=zhaogongyi@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox