From: poljar (Damir Jelić) Date: Thu, 16 Jan 2014 01:53:40 +0000 (+0100) Subject: strutil: Correctly parse floating point frequencies in parse_size_string(). X-Git-Tag: libsigrok-0.3.0~276 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=580f309948b1540a32cb1fd787ae3599c68cae4b;p=libsigrok.git strutil: Correctly parse floating point frequencies in parse_size_string(). parse_size_string() incorrectly parses a real number, e.g. 1.5 kHz ends up being 1Hz. This patch fixes parse_size_string() to take the fractional part as well into account. The fractional part is parsed as an double precision floating point number while ignoring the locale. --- diff --git a/strutil.c b/strutil.c index 17d59e8d..f4e48259 100644 --- a/strutil.c +++ b/strutil.c @@ -422,15 +422,20 @@ SR_API char **sr_parse_triggerstring(const struct sr_dev_inst *sdi, SR_API int sr_parse_sizestring(const char *sizestring, uint64_t *size) { int multiplier, done; + double frac_part; char *s; *size = strtoull(sizestring, &s, 10); multiplier = 0; + frac_part = 0; done = FALSE; while (s && *s && multiplier == 0 && !done) { switch (*s) { case ' ': break; + case '.': + frac_part = g_ascii_strtod(s, &s); + break; case 'k': case 'K': multiplier = SR_KHZ(1); @@ -449,8 +454,11 @@ SR_API int sr_parse_sizestring(const char *sizestring, uint64_t *size) } s++; } - if (multiplier > 0) + if (multiplier > 0) { *size *= multiplier; + *size += frac_part * multiplier; + } else + *size += frac_part; if (*s && strcasecmp(s, "Hz")) return SR_ERR;