From b639884f9ac78325b9a6658f23c9c245b8ac8263 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 30 May 2024 02:39:32 -0400 Subject: t-strvec: use va_end() to match va_start() Our check_strvec_loc() helper uses a variable argument list. When we va_start(), we must be sure to va_end() before leaving the function. This is required by the standard (though the effect of forgetting will vary between platforms). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/unit-tests/t-strvec.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 't') diff --git a/t/unit-tests/t-strvec.c b/t/unit-tests/t-strvec.c index f17fb10d9e..6c1465ee61 100644 --- a/t/unit-tests/t-strvec.c +++ b/t/unit-tests/t-strvec.c @@ -22,11 +22,13 @@ static void check_strvec_loc(const char *loc, struct strvec *vec, ...) strbuf_addf(&msg, "strvec index %"PRIuMAX, (uintmax_t) nr); test_assert(loc, msg.buf, 0); strbuf_release(&msg); + va_end(ap); return; } nr++; } + va_end(ap); check_uint(vec->nr, ==, nr); check_uint(vec->alloc, >=, nr); -- cgit v1.3-5-g9baa From 34eb843721bb3cd54e5fd1689d8f62bbba619bd9 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 30 May 2024 02:39:56 -0400 Subject: t-strvec: mark variable-arg helper with LAST_ARG_MUST_BE_NULL This will let the compiler catch a problem like: /* oops, we forgot the NULL */ check_strvec(&vec, "foo"); rather than triggering undefined behavior at runtime. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/unit-tests/t-strvec.c | 1 + 1 file changed, 1 insertion(+) (limited to 't') diff --git a/t/unit-tests/t-strvec.c b/t/unit-tests/t-strvec.c index 6c1465ee61..d4615ab06d 100644 --- a/t/unit-tests/t-strvec.c +++ b/t/unit-tests/t-strvec.c @@ -4,6 +4,7 @@ #define check_strvec(vec, ...) \ check_strvec_loc(TEST_LOCATION(), vec, __VA_ARGS__) +LAST_ARG_MUST_BE_NULL static void check_strvec_loc(const char *loc, struct strvec *vec, ...) { va_list ap; -- cgit v1.3-5-g9baa