Add terminating NUL after __func__ string literal #2920
This commit is contained in:
20
test/val/bug2920.c
Normal file
20
test/val/bug2920.c
Normal 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
|
||||
Reference in New Issue
Block a user