[linux-nfc] [neard][PATCH 03/16] mifare: use unsigned int to suppress compiler -Wstrict-overflow

Krzysztof Kozlowski <[email protected]>
Newsgroups org.01.lists.linux-nfc,dev.linux.lists.oe-linux-nfc
Message-ID <[email protected]>
GCC v7.5 (Ubuntu Bionic) with optimizations has trouble spotting lack of
possible overflow of a signed integer.  There is no overflow possible
so this is a false positive which can be suppressed by simply using
unsigned integer.  Unsigned also has more sense in that context.

This fixes GCC 7.5 warning:

    plugins/mifare.c: In function 'mifare_process_MADs':
    plugins/mifare.c:626:5: error: assuming signed overflow does not occur when simplifying conditional to constant [-Werror=strict-overflow]
      if (global_tag_size == 0) {
         ^

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
 plugins/mifare.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/plugins/mifare.c b/plugins/mifare.c
index a4e4ba443995..f42007d5dfd7 100644
--- a/plugins/mifare.c
+++ b/plugins/mifare.c
@@ -560,7 +560,7 @@ static int mifare_process_MADs(void *data)
 	struct mifare_cookie *mf_ck = data;
 	int err;
 	int i;
-	int global_tag_size = 0;
+	unsigned int global_tag_size = 0;
 	int ioffset;
 	uint8_t *tag_data;
 	size_t data_size;
@@ -626,13 +626,13 @@ done_mad:
 	if (global_tag_size == 0) {
 
 		/* no NFC sectors - mark tag as blank */
-		near_error("TAG Global size: [%d], not valid NFC tag.",
+		near_error("TAG Global size: [%u], not valid NFC tag.",
 				global_tag_size);
 		return -ENODEV;
 	}
 
 	/* n sectors, each sector is 3 blocks, each block is 16 bytes */
-	DBG("TAG Global size: [%d]", global_tag_size);
+	DBG("TAG Global size: [%u]", global_tag_size);
 
 	mf_ck->tag = near_tag_get_tag(mf_ck->adapter_idx, mf_ck->target_idx);
 	if (!mf_ck->tag) {
-- 
2.27.0
_______________________________________________
Linux-nfc mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.