From 35f6fd47fb4a58a7f335d5cf9ae4aa1899080678 Mon Sep 17 00:00:00 2001 From: Yorgos Thessalonikefs Date: Fri, 26 Sep 2025 16:22:00 +0200 Subject: [PATCH] - Test for nonstring attribute in configure and add nonstring attribute annotations. --- acx_nlnetlabs.m4 | 41 ++++++++++++++++++++++++++++++++++++++++- config.h.in | 14 ++++++++++++++ configure.ac | 2 ++ doc/Changelog | 4 ++++ util/data/msgreply.h | 11 +++++++---- 5 files changed, 67 insertions(+), 5 deletions(-) diff --git a/acx_nlnetlabs.m4 b/acx_nlnetlabs.m4 index 6a01dc5a4..c4dadc87a 100644 --- a/acx_nlnetlabs.m4 +++ b/acx_nlnetlabs.m4 @@ -490,7 +490,7 @@ AC_DEFUN([AHX_CONFIG_FORMAT_ATTRIBUTE], ]) dnl Check how to mark function arguments as unused. -dnl result in HAVE_ATTR_UNUSED. +dnl result in HAVE_ATTR_UNUSED. dnl Make sure you include AHX_CONFIG_UNUSED_ATTRIBUTE also. AC_DEFUN([ACX_CHECK_UNUSED_ATTRIBUTE], [AC_REQUIRE([AC_PROG_CC]) @@ -525,6 +525,45 @@ if test $ac_cv_c_unused_attribute = yes; then fi ])dnl +dnl Check how to mark function arguments as nonstring. +dnl result in HAVE_ATTR_NONSTRING. +dnl Make sure you include AHX_CONFIG_NONSTRING_ATTRIBUTE also. +AC_DEFUN([ACX_CHECK_NONSTRING_ATTRIBUTE], +[AC_REQUIRE([AC_PROG_CC]) +AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "nonstring" attribute) +AC_CACHE_VAL(ac_cv_c_nonstring_attribute, +[ac_cv_c_nonstring_attribute=no +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include +struct test { + char __attribute__((nonstring)) s[1]; +}; +]], [[ + struct test t = { "1" }; + (void) t; +]])],[ac_cv_c_nonstring_attribute="yes"],[ac_cv_c_nonstring_attribute="no"]) +]) + +dnl Setup ATTR_NONSTRING config.h parts. +dnl make sure you call ACX_CHECK_NONSTRING_ATTRIBUTE also. +AC_DEFUN([AHX_CONFIG_NONSTRING_ATTRIBUTE], +[ +#if defined(DOXYGEN) +# define ATTR_NONSTRING(x) x +#elif defined(__cplusplus) +# define ATTR_NONSTRING(x) __attribute__((nonstring)) x +#elif defined(HAVE_ATTR_NONSTRING) +# define ATTR_NONSTRING(x) __attribute__((nonstring)) x +#else /* !HAVE_ATTR_NONSTRING */ +# define ATTR_NONSTRING(x) x +#endif /* !HAVE_ATTR_NONSTRING */ +]) + +AC_MSG_RESULT($ac_cv_c_nonstring_attribute) +if test $ac_cv_c_nonstring_attribute = yes; then + AC_DEFINE(HAVE_ATTR_NONSTRING, 1, [Whether the C compiler accepts the "nonstring" attribute]) +fi +])dnl + dnl Pre-fun for ACX_LIBTOOL_C_ONLY AC_DEFUN([ACX_LIBTOOL_C_PRE], [ # skip these tests, we do not need them. diff --git a/config.h.in b/config.h.in index 10222cd12..7178cf7c0 100644 --- a/config.h.in +++ b/config.h.in @@ -72,6 +72,9 @@ /* Whether the C compiler accepts the "unused" attribute */ #undef HAVE_ATTR_UNUSED +/* Whether the C compiler accepts the "nonstring" attribute */ +#undef HAVE_ATTR_NONSTRING + /* Whether the C compiler accepts the "weak" attribute */ #undef HAVE_ATTR_WEAK @@ -1381,6 +1384,17 @@ #endif /* !HAVE_ATTR_UNUSED */ +#if defined(DOXYGEN) +# define ATTR_NONSTRING(x) x +#elif defined(__cplusplus) +# define ATTR_NONSTRING(x) __attribute__((nonstring)) x +#elif defined(HAVE_ATTR_NONSTRING) +# define ATTR_NONSTRING(x) __attribute__((nonstring)) x +#else /* !HAVE_ATTR_NONSTRING */ +# define ATTR_NONSTRING(x) x +#endif /* !HAVE_ATTR_NONSTRING */ + + #ifndef HAVE_FSEEKO #define fseeko fseek #define ftello ftell diff --git a/configure.ac b/configure.ac index 4ff4c0ef5..b5ff6717f 100644 --- a/configure.ac +++ b/configure.ac @@ -329,6 +329,7 @@ fi AC_C_INLINE ACX_CHECK_FORMAT_ATTRIBUTE ACX_CHECK_UNUSED_ATTRIBUTE +ACX_CHECK_NONSTRING_ATTRIBUTE AC_DEFUN([CHECK_WEAK_ATTRIBUTE], [AC_REQUIRE([AC_PROG_CC]) @@ -2292,6 +2293,7 @@ dnl includes AHX_CONFIG_FORMAT_ATTRIBUTE AHX_CONFIG_UNUSED_ATTRIBUTE +AHX_CONFIG_NONSTRING_ATTRIBUTE AHX_CONFIG_FSEEKO AHX_CONFIG_MAXHOSTNAMELEN #if !defined(HAVE_SNPRINTF) || defined(SNPRINTF_RET_BROKEN) diff --git a/doc/Changelog b/doc/Changelog index 110e0f95c..8e2d8aee0 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,7 @@ +26 September 2025: Yorgos + - Test for nonstring attribute in configure and add + nonstring attribute annotations. + 24 September 2025: Yorgos - Avoid calling mesh_detect_cycle_found() when there is no mesh state to begin with. diff --git a/util/data/msgreply.h b/util/data/msgreply.h index b78e40675..87eebb2b9 100644 --- a/util/data/msgreply.h +++ b/util/data/msgreply.h @@ -577,7 +577,7 @@ void log_query_info(enum verbosity_value v, const char* str, struct query_info* qinf); /** - * Append edns option to edns option list + * Append edns option to edns option list. * @param list: the edns option list to append the edns option to. * @param code: the edns option's code. * @param len: the edns option's length. @@ -589,17 +589,20 @@ int edns_opt_list_append(struct edns_option** list, uint16_t code, size_t len, uint8_t* data, struct regional* region); /** - * Append edns EDE option to edns options list + * Append edns EDE option to edns options list. + * We need ATTR_NONSTRING because we are trimming the trailing \0 of static + * string (TXT) when assigning to ede.text; it silences compiler nonstring + * warnings. * @param LIST: the edns option list to append the edns option to. * @param REGION: region to allocate the new edns option. * @param CODE: the EDE code. - * @param TXT: Additional text for the option + * @param TXT: Additional text for the option. */ #define EDNS_OPT_LIST_APPEND_EDE(LIST, REGION, CODE, TXT) \ do { \ struct { \ uint16_t code; \ - char text[sizeof(TXT) - 1]; \ + char ATTR_NONSTRING(text[sizeof(TXT) - 1]) ; \ } ede = { htons(CODE), TXT }; \ verbose(VERB_ALGO, "attached EDE code: %d with" \ " message: '%s'", CODE, TXT); \ -- 2.47.3