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.
This commit is contained in:
parent
0b92c32cb8
commit
580f309948
10
strutil.c
10
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)
|
SR_API int sr_parse_sizestring(const char *sizestring, uint64_t *size)
|
||||||
{
|
{
|
||||||
int multiplier, done;
|
int multiplier, done;
|
||||||
|
double frac_part;
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
*size = strtoull(sizestring, &s, 10);
|
*size = strtoull(sizestring, &s, 10);
|
||||||
multiplier = 0;
|
multiplier = 0;
|
||||||
|
frac_part = 0;
|
||||||
done = FALSE;
|
done = FALSE;
|
||||||
while (s && *s && multiplier == 0 && !done) {
|
while (s && *s && multiplier == 0 && !done) {
|
||||||
switch (*s) {
|
switch (*s) {
|
||||||
case ' ':
|
case ' ':
|
||||||
break;
|
break;
|
||||||
|
case '.':
|
||||||
|
frac_part = g_ascii_strtod(s, &s);
|
||||||
|
break;
|
||||||
case 'k':
|
case 'k':
|
||||||
case 'K':
|
case 'K':
|
||||||
multiplier = SR_KHZ(1);
|
multiplier = SR_KHZ(1);
|
||||||
|
@ -449,8 +454,11 @@ SR_API int sr_parse_sizestring(const char *sizestring, uint64_t *size)
|
||||||
}
|
}
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
if (multiplier > 0)
|
if (multiplier > 0) {
|
||||||
*size *= multiplier;
|
*size *= multiplier;
|
||||||
|
*size += frac_part * multiplier;
|
||||||
|
} else
|
||||||
|
*size += frac_part;
|
||||||
|
|
||||||
if (*s && strcasecmp(s, "Hz"))
|
if (*s && strcasecmp(s, "Hz"))
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
|
Loading…
Reference in New Issue