Skip to content

Commit a48ee56

Browse files
zuiderkwastmurphyjacob4
authored andcommitted
Fix undefined behaviour in bitops unit test (valkey-io#1786)
The unit test was added in valkey-io#1741. It fails when compiled with UBSAN. Using a local array like `char buf[size]` is undefined behaviour when `size == 0`. This fix just makes it size 1 in this case. The failure I got locally: unit/test_bitops.c:28:13: runtime error: variable length array bound evaluates to non-positive value 0 Signed-off-by: Viktor Söderqvist <[email protected]>
1 parent 522a569 commit a48ee56

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/unit/test_bitops.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ static long long bitcount(void *s, long count) {
2525
}
2626

2727
static int test_case(const char *msg, int size) {
28-
uint8_t buf[size];
28+
size_t bufsize = size > 0 ? size : 1;
29+
uint8_t buf[bufsize];
2930
int fuzzing = 1000;
3031
for (int y = 0; y < fuzzing; y += 1) {
3132
for (int z = 0; z < size; z += 1) {

0 commit comments

Comments
 (0)