[linux-nfc] [neard][PATCH 02/16] nfctool: annotate printf-like functions as accepting format

Krzysztof Kozlowski <[email protected]>
Newsgroups org.01.lists.linux-nfc,dev.linux.lists.oe-linux-nfc
Message-ID <[email protected]>
Printf-like functions should have the "format" argument annotated to:
1. Help in detection of format string vulnerabilities (and mistakes).
2. Satisfy -Wformat-nonliteral (-Wformat=2) warning.

This fixes clang warnings like:

    tools/nfctool/sniffer.c:206:18: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
                        sprintf(line, fmt, offset);
                                      ^~~

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
 tools/nfctool/sniffer.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/nfctool/sniffer.c b/tools/nfctool/sniffer.c
index 3d1d230a50c5..6a38a213c74d 100644
--- a/tools/nfctool/sniffer.c
+++ b/tools/nfctool/sniffer.c
@@ -168,7 +168,6 @@ void sniffer_print_hexdump(FILE *file, guint8 *data, guint32 len,
 	gchar *hexa = NULL, *human = NULL;
 	guint8 offset_len;
 	guint8 human_offset;
-	gchar *fmt;
 
 	if (len == 0)
 		return;
@@ -185,11 +184,9 @@ void sniffer_print_hexdump(FILE *file, guint8 *data, guint32 len,
 	if (output_len > 0xFFFF) {
 		offset_len = 8;
 		human_offset = HUMAN_READABLE_OFFSET + 4;
-		fmt = "%08X: ";
 	} else {
 		offset_len = 4;
 		human_offset = HUMAN_READABLE_OFFSET;
-		fmt = "%04X: ";
 	}
 
 	if (print_len) {
@@ -203,7 +200,10 @@ void sniffer_print_hexdump(FILE *file, guint8 *data, guint32 len,
 		if (digits == 0) {
 			memset(line, ' ', human_offset);
 
-			sprintf(line, fmt, offset);
+			if (offset_len == 8)
+				sprintf(line, "%08X: ", offset);
+			else
+				sprintf(line, "%04X: ", offset);
 
 			offset += 16;
 
-- 
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.