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.
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);
}
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;