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.
This commit is contained in:
Martin Ling 2018-09-20 01:45:22 +01:00 committed by Uwe Hermann
parent 755793e991
commit 5e5fde6e2c
1 changed files with 2 additions and 5 deletions

View File

@ -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;
return TRUE;
if (unit != prefix_friendly_units[i])
return FALSE;
return TRUE;
return FALSE;
}
/**