Skip to content

Commit

Permalink
Refactor uses of HAVE_PRINTF_STRING_NULL vs. REQUIRE_NUT_STRARG for p…
Browse files Browse the repository at this point in the history
…rintf("%s", NULL) support [#2109]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Oct 16, 2023
1 parent f3b11a6 commit 304d41e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion include/str.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ extern "C" {

/* Some compilers and/or C libraries do not handle printf("%s", NULL) correctly */
#ifndef NUT_STRARG
# ifdef HAVE_PRINTF_STRING_NULL
# if (defined REQUIRE_NUT_STRARG) && (REQUIRE_NUT_STRARG == 0)
# define NUT_STRARG(x) x
# else
/* Is required, or not defined => err on safe side */
# define NUT_STRARG(x) (x?x:"(null)")
# endif
#endif
Expand Down
14 changes: 8 additions & 6 deletions m4/ax_c_pragmas.m4
Original file line number Diff line number Diff line change
Expand Up @@ -1017,21 +1017,23 @@ if (res < 0) {
return 0;
]])],
[ax_cv__printf_string_null=yes
AM_CONDITIONAL([REQUIRE_NUT_STRARG], [false])
],
[ax_cv__printf_string_null=no
AC_DEFINE([REQUIRE_NUT_STRARG], [1],
[Define to 1 if your libc requires workarounds to print NULL values.])
AC_MSG_WARN([Your C library requires workarounds to print NULL values; if something crashes with a segmentation fault (especially during verbose debug) - that may be why])
AM_CONDITIONAL([REQUIRE_NUT_STRARG], [true])
],
[${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])
AM_CONDITIONAL([REQUIRE_NUT_STRARG], [false])
AC_DEFINE([REQUIRE_NUT_STRARG], [0],
[Define to 0 if your libc can printf("%s", NULL) sanely, or to 1 if your libc requires workarounds to print NULL values.])
],[
AM_CONDITIONAL([REQUIRE_NUT_STRARG], [true])
AC_DEFINE([REQUIRE_NUT_STRARG], [1],
[Define to 0 if your libc can printf("%s", NULL) sanely, or to 1 if your libc requires workarounds to print NULL values.])
AC_MSG_WARN([Your C library requires workarounds to print NULL values; if something crashes with a segmentation fault (especially during verbose debug) - that may be why])
])
AC_LANG_POP([C])
Expand Down
2 changes: 1 addition & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ nutlogtest-nofail.sh: nutlogtest$(EXEEXT)
@echo '#!/bin/sh' > $@
@echo 'echo "WARNING: Your C library requires workarounds to print NULL values!" >&2' >> $@
@echo 'echo "If nutlogtest below, or generally some NUT program, crashes with" >&2' >> $@
@echo 'echo "a segmentation fault (especially with verbose debug) - that may be why" >&2' >> $@
@echo 'echo "a segmentation fault (especially during verbose debug) - that may be why" >&2' >> $@
@echo 'SCRIPT_DIR="`dirname "$$0"`"' >> $@
@echo '"$${SCRIPT_DIR}/nutlogtest" "$$@" || echo "nutlogtest FAILED but it was expected"' >> $@
@chmod +x $@
Expand Down

0 comments on commit 304d41e

Please sign in to comment.