summaryrefslogtreecommitdiffstats
path: root/gl/m4/memchr.m4
diff options
context:
space:
mode:
authorLorenz <12514511+RincewindsHat@users.noreply.github.com>2023-03-11 10:34:47 (GMT)
committerGitHub <noreply@github.com>2023-03-11 10:34:47 (GMT)
commit75342b53853a898bdd93c7d3da9374115bab6b6d (patch)
tree0c0af2b796bcdd8ddd42187beb5badb420db8dea /gl/m4/memchr.m4
parent6bbe0b7b0f609ecab831dec9be7690842bf0a0fc (diff)
parent357787868b5201ec3e874e7a225b1c944cbbdb4d (diff)
downloadmonitoring-plugins-75342b53853a898bdd93c7d3da9374115bab6b6d.tar.gz
Merge branch 'master' into patch-1refs/pull/1842/head
Diffstat (limited to 'gl/m4/memchr.m4')
-rw-r--r--gl/m4/memchr.m474
1 files changed, 46 insertions, 28 deletions
diff --git a/gl/m4/memchr.m4 b/gl/m4/memchr.m4
index 2d8abe7..4f1aed0 100644
--- a/gl/m4/memchr.m4
+++ b/gl/m4/memchr.m4
@@ -1,35 +1,30 @@
1# memchr.m4 serial 12 1# memchr.m4 serial 18
2dnl Copyright (C) 2002-2004, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2004, 2009-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
6 6
7AC_DEFUN_ONCE([gl_FUNC_MEMCHR], 7AC_DEFUN_ONCE([gl_FUNC_MEMCHR],
8[ 8[
9 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
10
9 dnl Check for prerequisites for memory fence checks. 11 dnl Check for prerequisites for memory fence checks.
10 gl_FUNC_MMAP_ANON 12 gl_FUNC_MMAP_ANON
11 AC_CHECK_HEADERS_ONCE([sys/mman.h]) 13 AC_CHECK_HEADERS_ONCE([sys/mman.h])
12 AC_CHECK_FUNCS_ONCE([mprotect]) 14 AC_CHECK_FUNCS_ONCE([mprotect])
13 15
14 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) 16 AC_REQUIRE([gl_STRING_H_DEFAULTS])
15 m4_ifdef([gl_FUNC_MEMCHR_OBSOLETE], [ 17 # Detect platform-specific bugs in some versions of glibc:
16 dnl These days, we assume memchr is present. But if support for old 18 # memchr should not dereference anything with length 0
17 dnl platforms is desired: 19 # https://bugzilla.redhat.com/show_bug.cgi?id=499689
18 AC_CHECK_FUNCS_ONCE([memchr]) 20 # memchr should not dereference overestimated length after a match
19 if test $ac_cv_func_memchr = no; then 21 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=521737
20 HAVE_MEMCHR=0 22 # https://sourceware.org/bugzilla/show_bug.cgi?id=10162
21 fi 23 # memchr should cast the second argument to 'unsigned char'.
22 ]) 24 # This bug exists in Android 4.3.
23 if test $HAVE_MEMCHR = 1; then 25 # Assume that memchr works on platforms that lack mprotect.
24 # Detect platform-specific bugs in some versions of glibc: 26 AC_CACHE_CHECK([whether memchr works], [gl_cv_func_memchr_works],
25 # memchr should not dereference anything with length 0 27 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
26 # http://bugzilla.redhat.com/499689
27 # memchr should not dereference overestimated length after a match
28 # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=521737
29 # http://sourceware.org/bugzilla/show_bug.cgi?id=10162
30 # Assume that memchr works on platforms that lack mprotect.
31 AC_CACHE_CHECK([whether memchr works], [gl_cv_func_memchr_works],
32 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
33#include <string.h> 28#include <string.h>
34#if HAVE_SYS_MMAN_H 29#if HAVE_SYS_MMAN_H
35# include <fcntl.h> 30# include <fcntl.h>
@@ -64,6 +59,7 @@ AC_DEFUN_ONCE([gl_FUNC_MEMCHR],
64#endif 59#endif
65 if (fence) 60 if (fence)
66 { 61 {
62 /* Test against bugs on glibc systems. */
67 if (memchr (fence, 0, 0)) 63 if (memchr (fence, 0, 0))
68 result |= 1; 64 result |= 1;
69 strcpy (fence - 9, "12345678"); 65 strcpy (fence - 9, "12345678");
@@ -71,15 +67,37 @@ AC_DEFUN_ONCE([gl_FUNC_MEMCHR],
71 result |= 2; 67 result |= 2;
72 if (memchr (fence - 1, 0, 3) != fence - 1) 68 if (memchr (fence - 1, 0, 3) != fence - 1)
73 result |= 4; 69 result |= 4;
70 /* Test against bug on AIX 7.2. */
71 if (memchr (fence - 4, '6', 16) != fence - 4)
72 result |= 8;
74 } 73 }
74 /* Test against bug on Android 4.3. */
75 {
76 char input[3];
77 input[0] = 'a';
78 input[1] = 'b';
79 input[2] = 'c';
80 if (memchr (input, 0x789abc00 | 'b', 3) != input + 1)
81 result |= 16;
82 }
75 return result; 83 return result;
76]])], [gl_cv_func_memchr_works=yes], [gl_cv_func_memchr_works=no], 84]])],
77 [dnl Be pessimistic for now. 85 [gl_cv_func_memchr_works=yes],
78 gl_cv_func_memchr_works="guessing no"])]) 86 [gl_cv_func_memchr_works=no],
79 if test "$gl_cv_func_memchr_works" != yes; then 87 [case "$host_os" in
80 REPLACE_MEMCHR=1 88 # Guess no on Android.
81 fi 89 linux*-android*) gl_cv_func_memchr_works="guessing no" ;;
82 fi 90 # Guess yes on native Windows.
91 mingw*) gl_cv_func_memchr_works="guessing yes" ;;
92 # If we don't know, obey --enable-cross-guesses.
93 *) gl_cv_func_memchr_works="$gl_cross_guess_normal" ;;
94 esac
95 ])
96 ])
97 case "$gl_cv_func_memchr_works" in
98 *yes) ;;
99 *) REPLACE_MEMCHR=1 ;;
100 esac
83]) 101])
84 102
85# Prerequisites of lib/memchr.c. 103# Prerequisites of lib/memchr.c.