From: Bert Vermeulen Date: Mon, 24 Dec 2012 09:59:41 +0000 (+0100) Subject: fluke-dmm: parser cleanup X-Git-Tag: dsupstream~421 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=4cea0ff7febe335aa4607e544561710963d5e5af;p=libsigrok.git fluke-dmm: parser cleanup --- diff --git a/hardware/fluke-dmm/fluke.c b/hardware/fluke-dmm/fluke.c index eb7cfdc1..a855d4f4 100644 --- a/hardware/fluke-dmm/fluke.c +++ b/hardware/fluke-dmm/fluke.c @@ -17,17 +17,17 @@ * along with this program. If not, see . */ -#include -#include "libsigrok.h" -#include "libsigrok-internal.h" -#include "fluke-dmm.h" #include #include #include #include +#include +#include "libsigrok.h" +#include "libsigrok-internal.h" +#include "fluke-dmm.h" -static struct sr_datafeed_analog *handle_qm_v1(const struct sr_dev_inst *sdi, +static struct sr_datafeed_analog *handle_qm_18x(const struct sr_dev_inst *sdi, char **tokens) { struct sr_datafeed_analog *analog; @@ -37,7 +37,7 @@ static struct sr_datafeed_analog *handle_qm_v1(const struct sr_dev_inst *sdi, (void)sdi; - if (strcmp(tokens[0], "QM")) + if (strcmp(tokens[0], "QM") || !tokens[1]) return NULL; if ((e = strstr(tokens[1], "Out of range"))) { @@ -151,7 +151,7 @@ static struct sr_datafeed_analog *handle_qm_v1(const struct sr_dev_inst *sdi, return analog; } -static struct sr_datafeed_analog *handle_qm_v2(const struct sr_dev_inst *sdi, +static struct sr_datafeed_analog *handle_qm_28x(const struct sr_dev_inst *sdi, char **tokens) { struct sr_datafeed_analog *analog; @@ -160,6 +160,9 @@ static struct sr_datafeed_analog *handle_qm_v2(const struct sr_dev_inst *sdi, (void)sdi; + if (!tokens[1]) + return NULL; + fvalue = strtof(tokens[0], &eptr); if (fvalue == 0.0 && eptr == tokens[0]) { sr_err("Invalid float."); @@ -283,13 +286,13 @@ static void handle_line(const struct sr_dev_inst *sdi) analog = NULL; tokens = g_strsplit(devc->buf, ",", 0); - if (tokens[0] && tokens[1]) { + if (tokens[0]) { if (devc->profile->model == FLUKE_187) { devc->expect_response = FALSE; - analog = handle_qm_v1(sdi, tokens); + analog = handle_qm_18x(sdi, tokens); } else if (devc->profile->model == FLUKE_287) { devc->expect_response = FALSE; - analog = handle_qm_v2(sdi, tokens); + analog = handle_qm_28x(sdi, tokens); } } g_strfreev(tokens);