From a6e59e8b72e353266816c3fddbfb71cfd4f098fb Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Fri, 7 Mar 2025 00:35:49 +0800 Subject: [PATCH] Fix incorrect argument in 'do_size' error message Previously, the error message in 'do_size' referenced 'argv[2]' instead of 'argv[1]'. Since 'argc' is at most 2 in this context, 'argv[2]' is always null, as defined in Section 5.1.2.2.1 of the C11 standard. While GCC prints "(null)" for a null pointer in '%s' formatting, this behavior is implementation-defined. Other compilers may cause undefined behavior, potentially leading to a segmentation fault. This change ensures the correct argument is used, avoiding reliance on implementation-specific behavior and preventing potential crashes. Change-Id: I27748efd7c3d533659a6eda78f7c68ced2e78366 --- qtest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtest.c b/qtest.c index 43f14cc50..20f5ec1f5 100644 --- a/qtest.c +++ b/qtest.c @@ -544,7 +544,7 @@ static bool do_size(int argc, char *argv[]) bool ok = true; if (argc == 2) { if (!get_int(argv[1], &reps)) - report(1, "Invalid number of calls to size '%s'", argv[2]); + report(1, "Invalid number of calls to size '%s'", argv[1]); } int cnt = 0;