From: Martin Ling Date: Thu, 20 Sep 2018 00:45:22 +0000 (+0100) Subject: Fix read past end of array in sr_analog_si_prefix_friendly. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=5e5fde6e2c3aabfc61bcd35a53ab0d401b2176ba;p=libsigrok.git Fix read past end of array in sr_analog_si_prefix_friendly. In the case where the input unit was not in the array, the for loop would complete, but the following test would then read past the end of the array since 'i' would already have been incremented to the array size. Spotted because unitless data was getting SI prefixes with no unit, though this would not have been deterministically reproducible. This fixes parts of bug #950. --- diff --git a/src/analog.c b/src/analog.c index 6511de51..4eda290f 100644 --- a/src/analog.c +++ b/src/analog.c @@ -365,12 +365,9 @@ SR_API gboolean sr_analog_si_prefix_friendly(enum sr_unit unit) for (i = 0; i < ARRAY_SIZE(prefix_friendly_units); i++) if (unit == prefix_friendly_units[i]) - break; - - if (unit != prefix_friendly_units[i]) - return FALSE; + return TRUE; - return TRUE; + return FALSE; } /**