]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
UBSan: Avoid a warning on unsigned integer overflow
authorJouni Malinen <j@w1.fi>
Mon, 25 Feb 2019 00:57:41 +0000 (02:57 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 25 Feb 2019 17:48:49 +0000 (19:48 +0200)
wpa_non_pref_chan_cmp() needs to use explicit typecasts to avoid UBSan
warnings for unsigned integer overflows.

mbo.c:298:26: runtime error: unsigned integer overflow: 1 - 2 cannot be represented in type 'unsigned int'

Signed-off-by: Jouni Malinen <j@w1.fi>
wpa_supplicant/mbo.c

index bd5020a80d5c17ce80a180e472534de403d8ecea..d2f145114b17845ed5671f0b5ab457ddfc23296c 100644 (file)
@@ -293,10 +293,10 @@ static int wpa_non_pref_chan_cmp(const void *_a, const void *_b)
        const struct wpa_mbo_non_pref_channel *a = _a, *b = _b;
 
        if (a->oper_class != b->oper_class)
-               return a->oper_class - b->oper_class;
+               return (int) a->oper_class - (int) b->oper_class;
        if (a->reason != b->reason)
-               return a->reason - b->reason;
-       return a->preference - b->preference;
+               return (int) a->reason - (int) b->reason;
+       return (int) a->preference - (int) b->preference;
 }