ref: 5c8576383b7613dc8ff3d69dd435e56811da82ed
parent: bd3ce03103be4d98489d90f2f8c089edbb13bdc1
author: Jean-Marc Valin <jmvalin@jmvalin.ca>
date: Fri Mar 1 14:16:31 EST 2024
Fixes ubsan tests with clang Without the fix, ubsan would complain about some of the NULL pointer checks from test_opus_api.
--- a/include/opus_defines.h
+++ b/include/opus_defines.h
@@ -179,10 +179,20 @@
/* Macros to trigger compilation errors when the wrong types are provided to a CTL */
#define __opus_check_int(x) (((void)((x) == (opus_int32)0)), (opus_int32)(x))
+
+#ifdef DISABLE_PTR_CHECK
+/* Disable checks to prevent ubsan from complaining about NULL checks
+ in test_opus_api. */
+#define __opus_check_int_ptr(ptr) (ptr)
+#define __opus_check_uint_ptr(ptr) (ptr)
+#define __opus_check_uint8_ptr(ptr) (ptr)
+#define __opus_check_val16_ptr(ptr) (ptr)
+#else
#define __opus_check_int_ptr(ptr) ((ptr) + ((ptr) - (opus_int32*)(ptr)))
#define __opus_check_uint_ptr(ptr) ((ptr) + ((ptr) - (opus_uint32*)(ptr)))
#define __opus_check_uint8_ptr(ptr) ((ptr) + ((ptr) - (opus_uint8*)(ptr)))
#define __opus_check_val16_ptr(ptr) ((ptr) + ((ptr) - (opus_val16*)(ptr)))
+#endif
/** @endcond */
/** @defgroup opus_ctlvalues Pre-defined values for CTL interface
--- a/tests/random_config.sh
+++ b/tests/random_config.sh
@@ -39,7 +39,7 @@
footprint=`echo -e "\n-DSMALL_FOOTPRINT" | shuf -n1`
std=`echo -e "\n-std=c90\n-std=c99\n-std=c11\n-std=c17" | shuf -n1`
-sanitize=`echo -e "\n-fsanitize=address -fno-sanitize-recover=all\n-fsanitize=undefined -fno-sanitize-recover=all -fsanitize-recover=signed-integer-overflow" | shuf -n1`
+sanitize=`echo -e "\n-fsanitize=address -fno-sanitize-recover=all\n-fsanitize=undefined -fno-sanitize-recover=all -fsanitize-recover=signed-integer-overflow -DDISABLE_PTR_CHECK" | shuf -n1`
CFLAGS="$CFLAGS $std $opt $arch $footprint $math $sanitize"
--
⑨