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.
*/
#include <config.h>
+#include <ctype.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
errno = 0;
tmp = strtol(str, &endptr, 10);
+ while (endptr && isspace(*endptr))
+ endptr++;
+
if (!endptr || *endptr || errno) {
if (!errno)
errno = EINVAL;
errno = 0;
tmp = strtof(str, &endptr);
+ while (endptr && isspace(*endptr))
+ endptr++;
+
if (!endptr || *endptr || errno) {
if (!errno)
errno = EINVAL;