use AC_CHECK_DECLS to avoid implicit function definition

AC_CHECK_FUNCS is not safe, since implicit function definitions is just
a warning. On 64-bit glibc systems where reallocarray is not defined or
hidden behind macros that are not set, it gets implicitly defined to
return an integer, which is a big problem given that it should return a
pointer, and leads to immediate segfaults.
pull/249/head
Harmen Stoppels 2023-04-24 15:18:59 +02:00 committed by Ariadne Conill
parent b08733f45d
commit 40638f2472
2 changed files with 5 additions and 5 deletions

View File

@ -22,7 +22,7 @@ AX_CHECK_COMPILE_FLAG([-std=gnu99], [CFLAGS="$CFLAGS -std=gnu99"], [
AX_CHECK_COMPILE_FLAG([-std=c99], [CFLAGS="$CFLAGS -std=c99"])
])
AC_CONFIG_HEADERS([libpkgconf/config.h])
AC_CHECK_FUNCS([strlcpy strlcat strndup reallocarray])
AC_CHECK_DECLS([strlcpy, strlcat, strndup, reallocarray])
AC_CHECK_HEADERS([sys/stat.h])
AM_INIT_AUTOMAKE([foreign dist-xz subdir-objects])
AM_SILENT_RULES([yes])

View File

@ -25,7 +25,7 @@
#include <libpkgconf/bsdstubs.h>
#include <libpkgconf/config.h>
#ifndef HAVE_STRLCPY
#if !HAVE_DECL_STRLCPY
/*
* Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0).
@ -58,7 +58,7 @@ strlcpy(char *dst, const char *src, size_t siz)
}
#endif
#ifndef HAVE_STRLCAT
#if !HAVE_DECL_STRLCAT
/*
* Appends src to string dst of size siz (unlike strncat, siz is the
* full size of dst, not space left). At most siz-1 characters
@ -107,7 +107,7 @@ strlcat(char *dst, const char *src, size_t siz)
* from the use of this software.
*/
#ifndef HAVE_STRNDUP
#if !HAVE_DECL_STRNDUP
/*
* Creates a memory buffer and copies at most 'len' characters to it.
* If 'len' is less than the length of the source string, truncation occured.
@ -139,7 +139,7 @@ pkgconf_strndup(const char *src, size_t len)
return strndup(src, len);
}
#ifndef HAVE_REALLOCARRAY
#if !HAVE_DECL_REALLOCARRAY
void *
reallocarray(void *ptr, size_t m, size_t n)
{