From: Gerhard Sittig Date: Sat, 31 Dec 2016 13:25:07 +0000 (+0100) Subject: asyc-ii: Rephrase "exponent" logic when parsing packets X-Git-Tag: libsigrok-0.5.0~150 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=661aa24aa6f6715b615a566082c16fa643ebf955;p=libsigrok.git asyc-ii: Rephrase "exponent" logic when parsing packets Replace a C library strcspn(3) call with the more portable glib g_strstr_len(3) routine. This is possible since a single separator is searched for, no actual "set of characters" is involved. As a byproduct, this eliminates a "late" reference to 'cnt' at the bottom of the routine, after the value was assigned in a rather distant location at the top of the routine. The cost of strlen() should be acceptable for a buffer with a single digit total length. --- diff --git a/src/dmm/asycii.c b/src/dmm/asycii.c index 329f37e9..54858ffa 100644 --- a/src/dmm/asycii.c +++ b/src/dmm/asycii.c @@ -60,7 +60,8 @@ static int parse_value(const char *buf, struct asycii_info *info, { char valstr[7 + 1]; const char *valp; - int i, cnt, is_ol, dot_pos; + int i, cnt, is_ol; + const char *dot_pos; /* * Strip all spaces from bytes 0-6. By copying all @@ -102,12 +103,13 @@ static int parse_value(const char *buf, struct asycii_info *info, sr_spew("%s(), cannot convert number", __func__); return SR_ERR_DATA; } - dot_pos = strcspn(valstr, "."); - if (dot_pos < cnt) - *exponent = -(cnt - dot_pos - 1); + dot_pos = g_strstr_len(valstr, -1, "."); + if (dot_pos) + *exponent = -(valstr + strlen(valstr) - dot_pos - 1); else *exponent = 0; - sr_spew("%s(), display value is %f", __func__, *result); + sr_spew("%s(), display value is %f, exponent %d", + __func__, *result, *exponent); return SR_OK; }