[PATCH v5 1/3] cmdline: use C standard library as number parser
Bruce Richardson
bruce.richardson at intel.com
Thu May 8 09:27:41 CEST 2025
On Wed, May 07, 2025 at 04:22:10PM +0100, Anatoly Burakov wrote:
> Remove custom number parser and use C standard library instead. In order to
> keep compatibility with earlier versions of the parser, we have to take
> into account a few quirks:
>
> - We do not consider "negative" numbers to be valid for anything other than
> base-10 numbers, whereas C standard library does. We work around that by
> forcing base-10 when parsing numbers we expect to be negative.
Is it likely to break much in the way of compatibility if we start allowing
negative non-base-10 numbers? If it simplifies our code to allow it, I'd
tend towards doing so unless there is a known case where it might cause
problems.
/Bruce
> - We do not consider numbers such as "+4" to be valid, whereas C standard
> library does. No one probably relies on this, so we just remove it from
> our tests, as it is now a valid number.
> - C standard library's strtoull does not do range checks on negative
> numbers, so we have to parse knowingly-negative numbers as signed. We've
> already changed this to be the case on account of point 1 from this list,
> so no biggie.
> - C standard library does not support binary numbers, so we keep around the
> relevant parts of the custom parser in place to support binary numbers.
>
> Signed-off-by: Anatoly Burakov <anatoly.burakov at intel.com>
> ---
<snip>
More information about the dev
mailing list