From d13cfe10f61549b7869d09d6fd7371527b9aac90 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 7 Jun 2016 10:49:42 +0200 Subject: [PATCH] tests/tests1: fix printf format for size_t arguments MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change %d to %llu and add cast to unsigned long long for size_t arguments, otherwise compilation will fail with errors like: test1.c:70:15: error: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘size_t {aka long unsigned int}’ [-Werror=format=] %zu is avoided to stay compatible with old libc versions (like old Visual Studio). --- tests/test1.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test1.c b/tests/test1.c index 3d5b09a0..3cbd1860 100644 --- a/tests/test1.c +++ b/tests/test1.c @@ -67,7 +67,7 @@ void test_array_del_idx() for(ii = 0; ii < json_object_array_length(my_array); ii++) { json_object *obj = json_object_array_get_idx(my_array, ii); - printf("\t[%d]=%s\n", ii, json_object_to_json_string(obj)); + printf("\t[%llu]=%s\n", (unsigned long long)ii, json_object_to_json_string(obj)); } printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array)); @@ -88,16 +88,16 @@ void test_array_del_idx() // Delete all array indexes at once my_array = make_array(); rc = json_object_array_del_idx(my_array, 0, orig_array_len); - printf("after del_idx(0,%d)=%d, my_array.to_string()=%s\n", - orig_array_len, rc, json_object_to_json_string(my_array)); + printf("after del_idx(0,%llu)=%d, my_array.to_string()=%s\n", + (unsigned long long)orig_array_len, rc, json_object_to_json_string(my_array)); json_object_put(my_array); // Delete *more* than all array indexes at once my_array = make_array(); rc = json_object_array_del_idx(my_array, 0, orig_array_len + 1); - printf("after del_idx(0,%d)=%d, my_array.to_string()=%s\n", - orig_array_len + 1, rc, json_object_to_json_string(my_array)); + printf("after del_idx(0,%llu)=%d, my_array.to_string()=%s\n", + (unsigned long long)(orig_array_len + 1), rc, json_object_to_json_string(my_array)); json_object_put(my_array); } @@ -155,7 +155,7 @@ int main(int argc, char **argv) for(i=0; i < json_object_array_length(my_array); i++) { json_object *obj = json_object_array_get_idx(my_array, i); - printf("\t[%d]=%s\n", i, json_object_to_json_string(obj)); + printf("\t[%llu]=%s\n", (unsigned long long)i, json_object_to_json_string(obj)); } printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array)); @@ -172,7 +172,7 @@ int main(int argc, char **argv) for(i=0; i < json_object_array_length(my_array); i++) { json_object *obj = json_object_array_get_idx(my_array, i); - printf("\t[%d]=%s\n", i, json_object_to_json_string(obj)); + printf("\t[%llu]=%s\n", (unsigned long long)i, json_object_to_json_string(obj)); } printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array)); json_object_array_sort(my_array, sort_fn); @@ -180,7 +180,7 @@ int main(int argc, char **argv) for(i=0; i < json_object_array_length(my_array); i++) { json_object *obj = json_object_array_get_idx(my_array, i); - printf("\t[%d]=%s\n", i, json_object_to_json_string(obj)); + printf("\t[%llu]=%s\n", (unsigned long long)i, json_object_to_json_string(obj)); } printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array)); -- 2.39.5