From 2033519b0c76f8d78f06d3964805b54082a98226 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 18 Feb 2017 18:08:27 +0100 Subject: [PATCH] Add asserts to tell static analyzer we know what we're doing... nfc.c:1244:19: warning: Dereference of undefined pointer value for (int i = 0; nmt[i]; i++) { ^~~~~~ nfc.c:1256:23: warning: Dereference of undefined pointer value for (int j = 0; nbr[j]; j++) { ^~~~~~ --- libnfc/nfc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libnfc/nfc.c b/libnfc/nfc.c index 008d2e4..70312b8 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -79,6 +79,7 @@ #include #include #include +#include #include @@ -1237,13 +1238,14 @@ static int nfc_device_validate_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_modulation *nm) { int res; - const nfc_modulation_type *nmt; + const nfc_modulation_type *nmt = NULL; if ((res = nfc_device_get_supported_modulation(pnd, mode, &nmt)) < 0) { return res; } + assert(nmt != NULL); for (int i = 0; nmt[i]; i++) { if (nmt[i] == nm->nmt) { - const nfc_baud_rate *nbr; + const nfc_baud_rate *nbr = NULL; if (mode == N_INITIATOR) { if ((res = nfc_device_get_supported_baud_rate(pnd, nmt[i], &nbr)) < 0) { return res; @@ -1253,6 +1255,7 @@ nfc_device_validate_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_m return res; } } + assert(nbr != NULL); for (int j = 0; nbr[j]; j++) { if (nbr[j] == nm->nbr) return NFC_SUCCESS;