From c155f0500e90882d41709fbdc1b37cb479ed6249 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 4 Nov 2023 08:56:08 +0200 Subject: [PATCH 26/26] Meson: Add "zero-byte malloc()" check See osdn #48936 Signed-off-by: Marko Lindqvist --- gen_headers/meson_fc_config.h.in | 3 +++ meson.build | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/gen_headers/meson_fc_config.h.in b/gen_headers/meson_fc_config.h.in index 9d1f90054a..315d330942 100644 --- a/gen_headers/meson_fc_config.h.in +++ b/gen_headers/meson_fc_config.h.in @@ -416,3 +416,6 @@ /* Custom path to CA cert bundle */ #mesondefine CUSTOM_CACERT_PATH + +/* It's ok to call malloc() for zero bytes */ +#mesondefine MALLOC_ZERO_OK diff --git a/meson.build b/meson.build index 0f69747888..cfed0f9e08 100644 --- a/meson.build +++ b/meson.build @@ -982,6 +982,25 @@ void me::top() { [=, this]() {}; }; pub_conf_data.set('FREECIV_HAVE_CXX20_CAPTURE_THIS', 1) endif +zbm = c_compiler.run(''' +#include +int main() +{ + void *allocation = malloc(0); + + if (allocation != NULL) { + free(allocation); + } + + return (allocation == NULL); +}''', + name: 'zero-byte malloc()', + args: ['-Werror', '-Wall']) + +if zbm.returncode() == 0 + priv_conf_data.set('MALLOC_ZERO_OK', 1) +endif + configure_file(input : 'gen_headers/meson_fc_config.h.in', output : 'fc_config.h', configuration: priv_conf_data) -- 2.42.0