wext: avoid division by zero

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.
This commit is contained in:
Lubomir Rintel 2016-01-29 09:59:57 +01:00
parent 9b85179840
commit 503b714f15

View 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) /