From b996d07f322941ffd7b95f549d7ad204440eccd1 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 4 Mar 2025 14:41:13 +0100 Subject: [PATCH] os: drop our own implementation of reallocarray() --- hw/xfree86/xlibre-server.h.meson.in | 3 --- include/meson.build | 1 - include/os.h | 6 ----- os/meson.build | 3 --- os/reallocarray.c | 41 ----------------------------- 5 files changed, 54 deletions(-) delete mode 100644 os/reallocarray.c diff --git a/hw/xfree86/xlibre-server.h.meson.in b/hw/xfree86/xlibre-server.h.meson.in index c33d0f7d19..d14ac3d2f4 100644 --- a/hw/xfree86/xlibre-server.h.meson.in +++ b/hw/xfree86/xlibre-server.h.meson.in @@ -41,9 +41,6 @@ /* Add a padding for legacy nvidia drivers that support old ABI */ #mesondefine CONFIG_LEGACY_NVIDIA_PADDING -/* Define to 1 if you have the `reallocarray' function. */ -#mesondefine HAVE_REALLOCARRAY - /* Define to 1 if you have the `strcasestr' function. */ #mesondefine HAVE_STRCASESTR diff --git a/include/meson.build b/include/meson.build index 269265149b..233300d2a6 100644 --- a/include/meson.build +++ b/include/meson.build @@ -159,7 +159,6 @@ conf_data.set('HAVE_POLL', cc.has_function('poll') ? '1' : false) conf_data.set('HAVE_POLLSET_CREATE', cc.has_function('pollset_create') ? '1' : false) conf_data.set('HAVE_POSIX_FALLOCATE', cc.has_function('posix_fallocate') ? '1' : false) conf_data.set('HAVE_PORT_CREATE', cc.has_function('port_create') ? '1' : false) -conf_data.set('HAVE_REALLOCARRAY', cc.has_function('reallocarray', dependencies: libbsd_dep) ? '1' : false) conf_data.set('HAVE_SETEUID', cc.has_function('seteuid') ? '1' : false) conf_data.set('HAVE_SETITIMER', cc.has_function('setitimer') ? '1' : false) conf_data.set('HAVE_SHMCTL64', cc.has_function('shmctl64') ? '1' : false) diff --git a/include/os.h b/include/os.h index 519c465ce3..c251e9e545 100644 --- a/include/os.h +++ b/include/os.h @@ -211,12 +211,6 @@ TimeSinceLastInputEvent(void); /* Function fallbacks provided by AC_REPLACE_FUNCS in configure.ac */ -#ifndef HAVE_REALLOCARRAY -#define reallocarray xreallocarray -extern _X_EXPORT void * -reallocarray(void *optr, size_t nmemb, size_t size); -#endif - #ifndef HAVE_STRCASESTR #define strcasestr xstrcasestr extern _X_EXPORT char * diff --git a/os/meson.build b/os/meson.build index 8ad4c6447d..40271f34db 100644 --- a/os/meson.build +++ b/os/meson.build @@ -29,9 +29,6 @@ conf_data.set('CONFIG_SYSLOG', cc.has_header('syslog.h') ? '1' : false) # Wrapper code for missing C library functions. Note that conf_data contains either '1' or false. srcs_libc = [] -if conf_data.get('HAVE_REALLOCARRAY').to_int() == 0 - srcs_libc += 'reallocarray.c' -endif if conf_data.get('HAVE_STRCASESTR').to_int() == 0 srcs_libc += 'strcasestr.c' endif diff --git a/os/reallocarray.c b/os/reallocarray.c deleted file mode 100644 index 3c34f7ff9a..0000000000 --- a/os/reallocarray.c +++ /dev/null @@ -1,41 +0,0 @@ -/* $OpenBSD: reallocarray.c,v 1.2 2014/12/08 03:45:00 bcook Exp $ */ -/* - * Copyright (c) 2008 Otto Moerbeek - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include - -#include -#include -#include -#include -#include "os.h" - -/* - * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX - * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW - */ -#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) - -void * -reallocarray(void *optr, size_t nmemb, size_t size) -{ - if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && - nmemb > 0 && SIZE_MAX / nmemb < size) { - errno = ENOMEM; - return NULL; - } - return realloc(optr, size * nmemb); -}