From 89f402834cf018105909bfb002b09769b7a6c3fa Mon Sep 17 00:00:00 2001 From: "randomizedcoder dave.seddon.ca@gmail.com" Date: Fri, 18 Sep 2026 10:41:48 -0700 Subject: [PATCH] fix(devel): close va_list on every path in homa_snprintf homa_snprintf() called va_start(ap, format) at the top of the function but never called va_end(ap) on any of its return paths. The C standard requires each va_start to be paired with a va_end before the function returns; skipping it is undefined behavior and leaks the va_list on ABIs where va_start allocates (it is a no-op on the x86-64 SysV ABI, which is why no runtime failure is observed on this platform). Move va_start to just before the sole vsnprintf() call and va_end immediately after, so the va_list is opened and closed in one place and no early return can escape it. Gate: cppcheck --enable=all flags this as va_end_missing at homa_devel.c:490 before the fix and reports it clean after. The existing homa_snprintf unit regression stays green (test/unit homa_utils: 12/12). Co-Authored-By: Claude Opus 4.8 --- homa_devel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homa_devel.c b/homa_devel.c index 0e2f5ec9..e30bca7e 100644 --- a/homa_devel.c +++ b/homa_devel.c @@ -484,12 +484,12 @@ int homa_snprintf(char *buffer, int size, int used, const char *format, ...) int new_chars; va_list ap; - va_start(ap, format); - if (used >= (size - 1)) return used; + va_start(ap, format); new_chars = vsnprintf(buffer + used, size - used, format, ap); + va_end(ap); if (new_chars < 0) return used; if (new_chars >= (size - used))