From 30140b1a2d1ae3aa825d28a7e6cf9ac40bbabb8b Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 19 Dec 2021 14:56:52 +0200 Subject: [PATCH 36/43] Meson: Check for proper size_t printf() format See osdn #43390 Signed-off-by: Marko Lindqvist --- gen_headers/meson_fc_config.h.in | 3 +++ meson.build | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/gen_headers/meson_fc_config.h.in b/gen_headers/meson_fc_config.h.in index 09d670a9ce..f082dcdeae 100644 --- a/gen_headers/meson_fc_config.h.in +++ b/gen_headers/meson_fc_config.h.in @@ -63,6 +63,9 @@ /* Include git commit id to version string */ #mesondefine GITREV +/* Format specifier for size_t */ +#mesondefine SIZE_T_PRINTF + /* Can run programs as root */ #mesondefine ALWAYS_ROOT diff --git a/meson.build b/meson.build index c9dac77729..a8f48ae2b2 100644 --- a/meson.build +++ b/meson.build @@ -331,6 +331,23 @@ if get_option('cacert-path') != '' '"' + get_option('cacert-path') + '"') endif +potential_size_t_formats = [ '%zu', '%ld', '%lld', '%I64d' ] + +foreach format : potential_size_t_formats + if c_compiler.compiles('''#include +#if defined(__GNUC__) +void fr(const char *form, ...) + __attribute__((__format__(__printf__, 1, 2))); +#else +#define fr(_a_,_b_) printf(_a_,_b_) +#endif +int main(void) { size_t var = 0; fr("''' + format + '''", var); return 0; }''', + args: ['-Werror', '-Wall']) + priv_conf_data.set('SIZE_T_PRINTF', '"' + format + '"') + break + endif +endforeach + if get_option('audio') priv_conf_data.set('AUDIO_SDL', 1) -- 2.34.1