From cd6eeeeafe3bfed0bf57dc3e11af497ce43d5a12 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Mon, 29 Apr 2024 00:11:35 +0530 Subject: [PATCH] Fix some undefined behaviour in tests --- Makefile | 2 +- test/lib/test-base.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 51d430e..ffa1107 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CC=gcc VERBOSE=0 GENERAL-FLAGS:=-Wall -Wextra -Werror -Wswitch-enum -I$(shell pwd) -std=c11 -DEBUG-FLAGS=-ggdb -fsanitize=address +DEBUG-FLAGS=-ggdb -fsanitize=address -fsanitize=undefined RELEASE-FLAGS=-O3 CFLAGS:=$(GENERAL-FLAGS) $(DEBUG-FLAGS) -D VERBOSE=$(VERBOSE) diff --git a/test/lib/test-base.h b/test/lib/test-base.h index 19ba73d..82df48d 100644 --- a/test/lib/test-base.h +++ b/test/lib/test-base.h @@ -184,7 +184,7 @@ void test_lib_base_bytes_to_hword(void) } tests[] = {{{0, 0, 0, 0}, 0}, {{0xFF, 0xFF, 0xFF, 0xFF}, HWORD_MAX}, {{1, 0, 0, 0}, 1}, - {{0, 0, 0, 0b10000000}, 1 << 31}, + {{0, 0, 0, 0b10000000}, 1U << 31}, {{0x89, 0xab, 0xcd, 0xef}, 0xefcdab89}}; const size_t n = size_byte_array_to_string(4); @@ -247,7 +247,7 @@ void test_lib_base_hword_to_bytes(void) } tests[] = {{0, {0, 0, 0, 0}}, {HWORD_MAX, {0xFF, 0xFF, 0xFF, 0xFF}}, {1, {1, 0, 0, 0}}, - {1 << 31, {0, 0, 0, 0x80}}, + {1U << 31, {0, 0, 0, 0x80}}, {0xefcdab89, {0x89, 0xab, 0xcd, 0xef}}}; for (size_t i = 0; i < ARR_SIZE(tests); ++i)