[libcxx-commits] [PATCH] D99091: [locale][num_get] Improve Stage 2 of string to float conversion

Tomas Matheson via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Mar 22 10:18:44 PDT 2021

tmatheson created this revision.
tmatheson requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.


"Stage 2" of num_get::do_get() depends on "a check ... to determine if c is
allowed as the next character of an input field of the conversion specifier
returned by Stage 1". Previously this was a very simple check whether the next
character was in a set of allowed characters.  This could lead to Stage 2
accumulating character sequences such as "1.2f" and passing them to strtold
(Stage 3).

Stage 3 can fail, however, if the entire character sequence from Stage 2 is not
used in the conversion. For example, the "f" in "1.2f" is not used.

As a result, parsing a sequence like "1.2f" would return value 0.0 with failbit

This change improves the checks made in Stage 2, determining what is passed to
Stage 3.

- Hex digits are only considered valid if "0x" has been seen

- INFINITY value is recognised

- Characters in INFINITY and NAN are only valid in sequence. This is done by checking one character backwards, which has obvious limitations.

- New tests are added. The old ones are preserved but refactored.

  rG LLVM Github Monorepo



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99091.332350.patch
Type: text/x-patch
Size: 17289 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210322/90dd49c4/attachment-0001.bin>

More information about the libcxx-commits mailing list