From: Bert Vermeulen Date: Tue, 21 Jan 2014 16:02:27 +0000 (+0100) Subject: brymen-dmm: Make protocol parser locale-independent. X-Git-Tag: libsigrok-0.3.0~216 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=933e63a13bcedc7d4a003605449e54241e25f4eb;p=libsigrok.git brymen-dmm: Make protocol parser locale-independent. --- diff --git a/hardware/brymen-dmm/parser.c b/hardware/brymen-dmm/parser.c index 496ff3a0..e4b12274 100644 --- a/hardware/brymen-dmm/parser.c +++ b/hardware/brymen-dmm/parser.c @@ -158,12 +158,13 @@ static int parse_value(const char *strbuf, int len, float *floatval) } memset(str, 0, sizeof(str)); - /* Spaces may interfere with strtod parsing the exponent. Strip them. */ - for (s = 0, d = 0; s < len; s++) + /* Spaces may interfere with parsing the exponent. Strip them. */ + for (s = 0, d = 0; s < len; s++) { if (strbuf[s] != ' ') str[d++] = strbuf[s]; - /* Yes, it's that simple! */ - *floatval = strtod(str, NULL); + } + if (sr_atof_ascii(str, floatval) != SR_OK) + return SR_ERR; return SR_OK; } @@ -188,8 +189,8 @@ static void parse_flags(const uint8_t *buf, struct brymen_flags *info) info->is_ac = (buf[4 + 0] & (1 << 0)) != 0; } -SR_PRIV int sr_brymen_parse(const uint8_t *buf, float *floatval, - struct sr_datafeed_analog *analog, void *info) +SR_PRIV int brymen_parse(const uint8_t *buf, float *floatval, + struct sr_datafeed_analog *analog, void *info) { struct brymen_flags flags; struct brymen_header *hdr; @@ -211,7 +212,8 @@ SR_PRIV int sr_brymen_parse(const uint8_t *buf, float *floatval, sr_dbg("DMM packet: \"%.*s\"", asciilen, bfunc + 4); parse_flags(buf, &flags); - parse_value((const char *)(bfunc + 4), asciilen, floatval); + if (parse_value((const char *)(bfunc + 4), asciilen, floatval) != SR_OK) + return SR_ERR; if (flags.is_volt) { analog->mq = SR_MQ_VOLTAGE; diff --git a/hardware/brymen-dmm/protocol.c b/hardware/brymen-dmm/protocol.c index 4c33076a..97c58236 100644 --- a/hardware/brymen-dmm/protocol.c +++ b/hardware/brymen-dmm/protocol.c @@ -31,7 +31,8 @@ static void handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi) analog.num_samples = 1; analog.mq = -1; - sr_brymen_parse(buf, &floatval, &analog, NULL); + if (brymen_parse(buf, &floatval, &analog, NULL) != SR_OK) + return; analog.data = &floatval; analog.probes = sdi->probes; diff --git a/hardware/brymen-dmm/protocol.h b/hardware/brymen-dmm/protocol.h index 1270ecb6..5b6f787e 100644 --- a/hardware/brymen-dmm/protocol.h +++ b/hardware/brymen-dmm/protocol.h @@ -76,8 +76,8 @@ SR_PRIV int brymen_packet_request(struct sr_serial_dev_inst *serial); SR_PRIV int brymen_packet_length(const uint8_t *buf, int *len); SR_PRIV gboolean brymen_packet_is_valid(const uint8_t *buf); -SR_PRIV int sr_brymen_parse(const uint8_t *buf, float *floatval, - struct sr_datafeed_analog *analog, void *info); +SR_PRIV int brymen_parse(const uint8_t *buf, float *floatval, + struct sr_datafeed_analog *analog, void *info); SR_PRIV int brymen_stream_detect(struct sr_serial_dev_inst *serial, uint8_t *buf, size_t *buflen,