wext: avoid division by zero
authorLubomir Rintel <lkundrak@v3.sk>
Fri, 29 Jan 2016 08:59:57 +0000 (09:59 +0100)
committerLubomir Rintel <lkundrak@v3.sk>
Fri, 29 Jan 2016 19:18:22 +0000 (20:18 +0100)
Coverity is angry:

CID 59367 (#1-3 of 3): Division or modulo by float zero (DIVIDE_BY_ZERO)
30. divide_by_zero: In expression
  ((double)max_level - (double)level) /
  ((double)max_level - (double)noise),
division by expression (double)max_level - (double)noise which may be zero has
undefined behavior.

src/platform/wifi/wifi-utils-wext.c

index 96bcf53..85a387f 100644 (file)
@@ -315,7 +315,7 @@ wext_qual_to_percent (const struct iw_quality *qual,
                        noise = qual->noise - 0x100;
                else if ((max_qual->noise > 0) && !(max_qual->updated & IW_QUAL_NOISE_INVALID))
                        noise = max_qual->noise - 0x100;
-               noise = CLAMP (noise, FALLBACK_NOISE_FLOOR_DBM, FALLBACK_SIGNAL_MAX_DBM);
+               noise = CLAMP (noise, FALLBACK_NOISE_FLOOR_DBM, FALLBACK_SIGNAL_MAX_DBM - 1);
 
                /* A sort of signal-to-noise ratio calculation */
                level_percent = (int) (100 - 70 * (((double)max_level - (double)level) /