@@ -597,7 +597,7 @@ static void test_visitor_in_list_struct(TestInputVisitorData *data,
for (str_list = arrs->string; str_list; str_list = str_list->next) {
char expected[32];
- sprintf(expected, "%d", i);
+ snprintf(expected, sizeof(expected), "%d", i);
g_assert_cmpstr(str_list->value, ==, expected);
i++;
}
@@ -595,7 +595,7 @@ static void test_visitor_out_list_struct(TestOutputVisitorData *data,
char expected[32];
g_assert(qvalue);
- sprintf(expected, "%d", i);
+ snprintf(expected, sizeof(expected), "%d", i);
g_assert_cmpstr(qstring_get_str(qvalue), ==, expected);
i++;
}
@@ -1028,12 +1028,13 @@ static void add_visitor_type(const SerializeOps *ops)
TestArgs *args;
int i = 0;
- sprintf(testname_prefix, "/visitor/serialization/%s", ops->type);
+ snprintf(testname_prefix, sizeof(testname_prefix),
+ "/visitor/serialization/%s", ops->type);
if (ops->caps & VCAP_PRIMITIVES) {
while (pt_values[i].type != PTYPE_EOL) {
- sprintf(testname, "%s/primitives/%s", testname_prefix,
- pt_values[i].description);
+ snprintf(testname, sizeof(testname), "%s/primitives/%s",
+ testname_prefix, pt_values[i].description);
args = g_malloc0(sizeof(*args));
args->ops = ops;
args->test_data = &pt_values[i];
@@ -1043,13 +1044,14 @@ static void add_visitor_type(const SerializeOps *ops)
}
if (ops->caps & VCAP_STRUCTURES) {
- sprintf(testname, "%s/struct", testname_prefix);
+ snprintf(testname, sizeof(testname), "%s/struct", testname_prefix);
args = g_malloc0(sizeof(*args));
args->ops = ops;
args->test_data = NULL;
g_test_add_data_func(testname, args, test_struct);
- sprintf(testname, "%s/nested_struct", testname_prefix);
+ snprintf(testname, sizeof(testname),
+ "%s/nested_struct", testname_prefix);
args = g_malloc0(sizeof(*args));
args->ops = ops;
args->test_data = NULL;
@@ -1057,7 +1059,8 @@ static void add_visitor_type(const SerializeOps *ops)
}
if (ops->caps & VCAP_LISTS) {
- sprintf(testname, "%s/nested_struct_list", testname_prefix);
+ snprintf(testname, sizeof(testname),
+ "%s/nested_struct_list", testname_prefix);
args = g_malloc0(sizeof(*args));
args->ops = ops;
args->test_data = NULL;
@@ -1067,8 +1070,8 @@ static void add_visitor_type(const SerializeOps *ops)
if (ops->caps & VCAP_PRIMITIVE_LISTS) {
i = 0;
while (pt_values[i].type != PTYPE_EOL) {
- sprintf(testname, "%s/primitive_list/%s", testname_prefix,
- pt_values[i].description);
+ snprintf(testname, sizeof(testname), "%s/primitive_list/%s",
+ testname_prefix, pt_values[i].description);
args = g_malloc0(sizeof(*args));
args->ops = ops;
args->test_data = &pt_values[i];
Replace sprintf() by safer snprintf() to avoid when using Apple clang 17.0.0 on macOS ARM64: ../tests/unit/test-qobject-output-visitor.c:598:9: warning: 'sprintf' is deprecated [-Wdeprecated-declarations] ../tests/unit/test-qobject-input-visitor.c:600:9: warning: 'sprintf' is deprecated [-Wdeprecated-declarations] ../tests/unit/test-visitor-serialization.c:1031:5: warning: 'sprintf' is deprecated [-Wdeprecated-declarations] ../tests/unit/test-visitor-serialization.c:1035:13: warning: 'sprintf' is deprecated [-Wdeprecated-declarations] ... Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> --- tests/unit/test-qobject-input-visitor.c | 2 +- tests/unit/test-qobject-output-visitor.c | 2 +- tests/unit/test-visitor-serialization.c | 19 +++++++++++-------- 3 files changed, 13 insertions(+), 10 deletions(-)