From 8ce45a1bee1e82fe8d36559781c8161575650232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= Date: Sun, 5 Feb 2023 22:32:42 -0800 Subject: [PATCH] improve __buitin_mul_overflow() checks Use as a source for size_t as suggested by ANSI in preference to (as suggested by POSIX), and make sure that the check includes linkin so it won't result in a false positive in platforms that allow link time resolution of unknown objects (ex: AIX with lxc) --- CMakeLists.txt | 2 +- configure.ac | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c834798d7..b2915f855 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,7 +164,7 @@ set(ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror") CHECK_C_SOURCE_COMPILES( - "#include + "#include int main() { int a,b; size_t m; __builtin_mul_overflow(a,b,&m); return 0; }" HAVE_BUILTIN_MUL_OVERFLOW ) diff --git a/configure.ac b/configure.ac index f31bd09ff..94c99a4b2 100644 --- a/configure.ac +++ b/configure.ac @@ -77,15 +77,12 @@ PCRE2_VISIBILITY AC_MSG_CHECKING([for __builtin_mul_overflow()]) AC_LANG_PUSH([C]) -tmp_CFLAGS=$CFLAGS -CFLAGS="$CFLAGS -Werror" -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #ifdef HAVE_SYS_TYPES_H #include #endif - #ifdef HAVE_STDLIB_H - #include - #endif + #include + int a, b; size_t m; ]], [[__builtin_mul_overflow(a, b, &m)]])], @@ -96,7 +93,6 @@ if test "$pcre2_cc_cv_builtin_mul_overflow" = yes; then AC_DEFINE([HAVE_BUILTIN_MUL_OVERFLOW], 1, [Define this if your compiler provides __builtin_mul_overflow()]) fi -CFLAGS=$tmp_CFLAGS AC_LANG_POP([C]) # Check for Clang __attribute__((uninitialized)) feature