[linux-nfc] [neard][PATCH 32/34] unit: use proper format for integers (-Wformat)

Krzysztof Kozlowski <[email protected]>
Newsgroups org.01.lists.linux-nfc,dev.linux.lists.oe-linux-nfc
Message-ID <[email protected]>
Properly print signed and unsigned integers.  This fixes warnings like:

    unit/test-ndef-parse.c: In function ‘test_ndef_single_sp’:
    unit/test-ndef-parse.c:318:33: error: field precision specifier ‘.*’ expects argument of type ‘int’, but argument 2 has type ‘uint32_t’ {aka ‘unsigned int’} [-Werror=format=]
      318 |   g_print("NDEF SP URI field: %.*s\n", uri->field_length,
          |                               ~~^~     ~~~~~~~~~~~~~~~~~
          |                                 |         |
          |                                 int       uint32_t {aka unsigned int}

    unit/test-snep-read.c: In function ‘test_snep_dummy_req_put’:
    unit/test-snep-read.c:42:12: error: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘uint32_t’ {aka ‘unsigned int’} [-Werror=format=]
       42 |   g_printf("[SNEP unit] " fmt, ##__VA_ARGS__); \
          |            ^~~~~~~~~~~~~~
    ......
      118 |     frag_cnt, fragment->nfc_data_length,
          |               ~~~~~~~~~~~~~~~~~~~~~~~~~
          |                       |
          |                       uint32_t {aka unsigned int}

    unit/test-snep-read.c: In function ‘test_snep_read_verify_resp’:
    unit/test-snep-read.c:42:12: error: format ‘%X’ expects argument of type ‘unsigned int’, but argument 3 has type ‘int’ [-Werror=format=]
       42 |   g_printf("[SNEP unit] " fmt, ##__VA_ARGS__); \
          |            ^~~~~~~~~~~~~~
    ......
      454 |    resp->response, exp_resp_code);
          |                    ~~~~~~~~~~~~~
          |                    |
          |                    int

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
 unit/test-ndef-parse.c | 8 ++++----
 unit/test-snep-read.c  | 6 +++---
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/unit/test-ndef-parse.c b/unit/test-ndef-parse.c
index cdeb1a1a24df..0bc53eeac125 100644
--- a/unit/test-ndef-parse.c
+++ b/unit/test-ndef-parse.c
@@ -315,8 +315,8 @@ static void test_ndef_single_sp(void)
 					uri->field_length) == 0);
 
 	if (g_test_verbose())
-		g_print("NDEF SP URI field: %.*s\n", uri->field_length,
-							(char *) uri->field);
+		g_print("NDEF SP URI field: %.*s\n", (int)uri->field_length,
+			(char *) uri->field);
 
 	g_free(uri->field);
 	g_free(uri);
@@ -359,8 +359,8 @@ static void test_ndef_title_sp(void)
 					uri->field_length) == 0);
 
 	if (g_test_verbose())
-		g_print("NDEF SP URI field: %.*s\n", uri->field_length,
-							(char *) uri->field);
+		g_print("NDEF SP URI field: %.*s\n", (int)uri->field_length,
+			(char *) uri->field);
 
 	g_assert_cmpstr(text->data, ==, "Intel");
 	g_assert_cmpstr(text->encoding, ==, "UTF-8");
diff --git a/unit/test-snep-read.c b/unit/test-snep-read.c
index 78db58ba859f..414b801a5e71 100644
--- a/unit/test-snep-read.c
+++ b/unit/test-snep-read.c
@@ -114,7 +114,7 @@ static bool test_snep_dummy_req_put(int fd, void *data)
 		static int frag_cnt;
 		struct p2p_snep_data *fragment = test_fragments->data;
 
-		TEST_SNEP_LOG("\tdummy_req_put frag=%d, len=%d, current=%d\n",
+		TEST_SNEP_LOG("\tdummy_req_put frag=%d, len=%u, current=%u\n",
 				frag_cnt, fragment->nfc_data_length,
 				fragment->nfc_data_current_length);
 		test_fragments = g_slist_remove(test_fragments, fragment);
@@ -437,7 +437,7 @@ static void test_snep_read_no_response(void)
  * @param[in] exp_resp_info_len  Expected response info length
  * @param[in] exp_resp_info      Expected response info
  */
-static void test_snep_read_verify_resp(int exp_resp_code,
+static void test_snep_read_verify_resp(uint8_t exp_resp_code,
 		uint32_t exp_resp_info_len, uint8_t *exp_resp_info)
 {
 	struct p2p_snep_resp_frame *resp;
@@ -467,7 +467,7 @@ static void test_snep_read_verify_resp(int exp_resp_code,
  *
  * @param[in] exp_resp_code  Expected response code
  */
-static void test_snep_read_verify_resp_code(int exp_resp_code)
+static void test_snep_read_verify_resp_code(uint8_t exp_resp_code)
 {
 	test_snep_read_verify_resp(exp_resp_code, 0, NULL);
 }
-- 
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.