mirror of https://github.com/nirenjan/libx52.git
fix: Handle negative index in libx52-string-test
The test case uses a negative value to force a test of the ID to string functions in the abnormal case. However, this ends up with accessing the expected array with a negative index. This is technically undefined behavior, and may cause failures in some systems. This change ensures that the negative values will be mapped directly to the unknown string, without having to perform a negative index.pull/58/head
parent
ef4cbee127
commit
762a3468b2
|
|
@ -18,7 +18,9 @@
|
|||
#define TEST_STRINGIFY(name) do { \
|
||||
char expected[256]; \
|
||||
for (int i=-1; i < sizeof(name ## _map) / sizeof(name ## _map[0]); i++) { \
|
||||
if (name ## _map[i] != NULL) { \
|
||||
if (i < 0) { \
|
||||
snprintf(expected, sizeof(expected), unknown_fmt, i); \
|
||||
} else if (name ## _map[i] != NULL) { \
|
||||
strncpy(expected, name ## _map[i], sizeof(expected)); \
|
||||
} else { \
|
||||
snprintf(expected, sizeof(expected), unknown_fmt, i); \
|
||||
|
|
|
|||
Loading…
Reference in New Issue