Skip to content

Commit

Permalink
m4/ax_c_pragmas.m4: extend AX_C_PRINTF_STRING_NULL with use of AX_RUN…
Browse files Browse the repository at this point in the history
…_OR_LINK_IFELSE option to ignore certain warnings [networkupstools#2109]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Oct 16, 2023
1 parent 35c4001 commit aae6f44
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion m4/ax_c_pragmas.m4
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,13 @@ if test -z "${nut_have_ax_c_printf_string_null_seen}"; then
nut_have_ax_c_printf_string_null_seen="yes"
AC_REQUIRE([AX_RUN_OR_LINK_IFELSE])dnl
dnl Here we do not care if the compiler formally complains about
dnl undefined behavior of printf("%s", NULL) as long as it works
dnl in practice (compiler or libc implement a sane fallback):
myWARN_CFLAGS=""
AS_IF([test "${GCC}" = "yes" || test "${CLANGCC}" = "yes"],
[myWARN_CFLAGS="-Wno-format-truncation -Wno-format-overflow"])
dnl ### To be sure, bolt the language
AC_LANG_PUSH([C])
Expand All @@ -979,6 +986,9 @@ if test -z "${nut_have_ax_c_printf_string_null_seen}"; then
], [[
char buf[128];
char *s = NULL;
/* The following line may issue pedantic static analysis warnings (ignored);
* it may also crash (segfault) during a run on some systems - hence the test.
*/
int res = snprintf(buf, sizeof(buf), "%s", s);
buf[sizeof(buf)-1] = '\0';
if (res < 0) {
Expand All @@ -997,9 +1007,11 @@ fprintf(stderr, "SUCCESS: RETURNED a string that contains something like 'null'
return 0;
]])],
[ax_cv__printf_string_null=yes],
[ax_cv__printf_string_null=no]
[ax_cv__printf_string_null=no],
[${myWARN_CFLAGS}]
)]
)
unset myWARN_CFLAGS
AS_IF([test "$ax_cv__printf_string_null" = "yes"],[
AC_DEFINE([HAVE_PRINTF_STRING_NULL], 1, [define if your libc can printf("%s", NULL) sanely])
Expand Down

0 comments on commit aae6f44

Please sign in to comment.