From: Alexandru Gagniuc Date: Fri, 30 Nov 2012 19:11:04 +0000 (-0600) Subject: metex14: Fix parsing of measurement flags. X-Git-Tag: dsupstream~511 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3ebc9b59a2e2b96ad95dbfdf3218c3b3b00940ef;p=libsigrok.git metex14: Fix parsing of measurement flags. strcmp(buf + 9, " mA") does not work because buf is CR-terminated, while " mA" is NUL-terminated. Drop ambiguities arising from the termination of the strings, and only compare the characters we care about, using strncmp(). Signed-off-by: Alexandru Gagniuc --- diff --git a/hardware/common/dmm/metex14.c b/hardware/common/dmm/metex14.c index 9364dcb0..7afae5f9 100644 --- a/hardware/common/dmm/metex14.c +++ b/hardware/common/dmm/metex14.c @@ -135,27 +135,27 @@ static void parse_flags(const char *buf, struct metex14_info *info) /* Bytes 3-8: See parse_value(). */ /* Bytes 9-12: Unit */ - if (!strcmp(buf + 9, " A")) + if (!strncmp(buf + 9, " A", 4)) info->is_ampere = TRUE; - else if (!strcmp(buf + 9, " mA")) + else if (!strncmp(buf + 9, " mA", 4)) info->is_milli = info->is_ampere = TRUE; - else if (!strcmp(buf + 9, " V")) + else if (!strncmp(buf + 9, " V", 4)) info->is_volt = TRUE; - else if (!strcmp(buf + 9, " mV")) + else if (!strncmp(buf + 9, " mV", 4)) info->is_milli = info->is_volt = TRUE; - else if (!strcmp(buf + 9, " Ohm")) + else if (!strncmp(buf + 9, " Ohm", 4)) info->is_ohm = TRUE; - else if (!strcmp(buf + 9, "KOhm")) + else if (!strncmp(buf + 9, "KOhm", 4)) info->is_kilo = info->is_ohm = TRUE; - else if (!strcmp(buf + 9, "MOhm")) + else if (!strncmp(buf + 9, "MOhm", 4)) info->is_mega = info->is_ohm = TRUE; - else if (!strcmp(buf + 9, " nF")) + else if (!strncmp(buf + 9, " nF", 4)) info->is_nano = info->is_farad = TRUE; - else if (!strcmp(buf + 9, " uF")) + else if (!strncmp(buf + 9, " uF", 4)) info->is_micro = info->is_farad = TRUE; - else if (!strcmp(buf + 9, " KHz")) + else if (!strncmp(buf + 9, " KHz", 4)) info->is_kilo = info->is_hertz = TRUE; - else if (!strcmp(buf + 9, " C")) + else if (!strncmp(buf + 9, " C", 4)) info->is_celsius = TRUE; /* Byte 13: Always '\r' (carriage return, 0x0d, 13) */