From: Gerhard Sittig Date: Sun, 4 Feb 2018 19:17:08 +0000 (+0100) Subject: strutil: accept trailing whitespace after number text X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=b8278e0943317cdf6594057ae9482c786c607f04 strutil: accept trailing whitespace after number text Some SCPI based drivers fail to convert response data, because strutil conversion helpers sr_atol() and sr_atof() don't like trailing spaces after the number's text that successfully got converted. It's yet to get determined whether all call sites of the conversion routines like their eating adjacent whitespace. But given that the conversion routine explicitly checks for end of the string after the number, no call site should expect or even depend on trailing text to keep its whitespace. See bug #788 for a discussion and example data. --- diff --git a/src/strutil.c b/src/strutil.c index 3fe59551..5344ec29 100644 --- a/src/strutil.c +++ b/src/strutil.c @@ -18,6 +18,7 @@ */ #include +#include #include #include #include @@ -67,6 +68,9 @@ SR_PRIV int sr_atol(const char *str, long *ret) errno = 0; tmp = strtol(str, &endptr, 10); + while (endptr && isspace(*endptr)) + endptr++; + if (!endptr || *endptr || errno) { if (!errno) errno = EINVAL; @@ -129,6 +133,9 @@ SR_PRIV int sr_atod(const char *str, double *ret) errno = 0; tmp = strtof(str, &endptr); + while (endptr && isspace(*endptr)) + endptr++; + if (!endptr || *endptr || errno) { if (!errno) errno = EINVAL;