]> sigrok.org Git - libsigrok.git/commit - src/strutil.c
strutil: avoid glib/platform conversion calls for empty input
authorGerhard Sittig <redacted>
Thu, 19 Jul 2018 19:17:16 +0000 (21:17 +0200)
committerGerhard Sittig <redacted>
Sun, 21 Aug 2022 15:45:11 +0000 (17:45 +0200)
commitca9949980b146606a8f61f926004d1a6fb27a2a7
tree6354c6ab86fdea24bc3aa5801961e0129f58af2d
parentdd143eb2c781c46bc3a7efd66d259e4b1390e1d2
strutil: avoid glib/platform conversion calls for empty input

It appears that either glib or some underlying platform library code for
text to number conversion yields unexpected values for return codes,
errno, and "end pointer" when _none_ of the input could get converted.
This was reported for MacOS, did not reproduce on Linux. The reported
issue was addressed in commit 51bf39a1633c, this implementation is just
much more conservative and hopefully easier to verify since it's more
explicit.

Rephrase the rational text to number conversion to avoid the problematic
input cases. Address style nits while we are here in the hope to improve
readability: Move initial assignment and subsequent updates of variables
closer together for easier verification.

Accept optional leading whitespace. Accept numbers like "123." in
addition to the previously supported ".123" formats. But insist that one
of the integral or fractional parts must be present. Try harder to setup
non-zero errno values for other failed conversion attempts beyond failed
library calls (the strtol(3) manpage suggests so in the ERRORS section).

This implementation passes on Linux, but has not been tested with MacOS
which appears to have a pickier library implementation.
src/strutil.c