Add terminating NUL after __func__ string literal #2920

This commit is contained in:
Willis Blackburn
2026-01-24 12:09:55 -05:00
parent 034f73a9e1
commit 789416798f
2 changed files with 21 additions and 0 deletions

20
test/val/bug2920.c Normal file
View File

@@ -0,0 +1,20 @@
#include "unittest.h"
TEST {
/* The bug causes __func__ to be not null terminated. */
const char *f = __func__;
size_t size = sizeof(__func__);
size_t i;
/* Ensure the size is correct (5 for "main" + null terminator) */
ASSERT_AreEqual((unsigned)size, 5u, "%u", "Sizeof __func__ should be 5");
/* Check content */
for (i = 0; i < size - 1; ++i) {
ASSERT_AreEqual(f[i], "main"[i], "%c", "Character mismatch");
}
/* Check null terminator specifically */
ASSERT_AreEqual(f[size - 1], '\0', "%02X", "Null terminator missing");
}
ENDTEST