X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fstrutil.c;h=68a9004e609339de53560dc7fb29c0605e51c465;hb=41c47f2c6ac4cb7531588bd38c55af2484523385;hp=fd9a438e647a6210e63091050b78c7790ffe97be;hpb=f05600f4be54c7f112815cc1624600517243898e;p=libsigrok.git diff --git a/src/strutil.c b/src/strutil.c index fd9a438e..68a9004e 100644 --- a/src/strutil.c +++ b/src/strutil.c @@ -233,13 +233,19 @@ SR_API int sr_parse_rational(const char *str, struct sr_rational *ret) int64_t denominator = 1; int32_t fractional_len = 0; int32_t exponent = 0; + int is_negative = 0; errno = 0; integral = g_ascii_strtoll(str, &endptr, 10); - if (errno) + if (str == endptr && (str[0] == '-' || str[0] == '+') && str[1] == '.') + endptr += 1; + else if (errno) return SR_ERR; + if (integral < 0 || str[0] == '-') + is_negative = 1; + if (*endptr == '.') { const char* start = endptr + 1; fractional = g_ascii_strtoll(start, &endptr, 10); @@ -261,7 +267,7 @@ SR_API int sr_parse_rational(const char *str, struct sr_rational *ret) integral *= 10; exponent -= fractional_len; - if (integral >= 0) + if (!is_negative) integral += fractional; else integral -= fractional;