From df25ff7ce0e42ea6a489cff2386774887a7dbd37 Mon Sep 17 00:00:00 2001 From: Andreas Gnau Date: Mon, 15 Dec 2025 13:22:32 +0100 Subject: [PATCH] libbbfdm-api: proper parenthesis in macros When using macros, both any occurence of arguments and the macro itself have to be enclosed in parenthesis to prevent unintended behaviour with operator precedence. For now, only fix the one causing a -Wint-conversion warning in GCC 14 when using constructs like these, where two macros are used together and expand to both two comparisons and two nested ternary expression. dhcpmngr.c:502:41: error: pointer/integer type mismatch in conditional expression [-Wint-conversion] 502 | if (DM_STRCMP(parent_s, section_name(s)) != 0) Given the very heavy use of macros in this project, there are probably more instances of this issue in the code and it can cause actual logic errors. While at it, double evaluation should also be checked for. Link: http://web.archive.org/web/20140127211232/http://docs.freebsd.org/info/cpp/cpp.info.Macro_Parentheses.html Link: https://clang.llvm.org/extra/clang-tidy/checks/bugprone/macro-parentheses.html Signed-off-by: Andreas Gnau --- libbbfdm-api/legacy/dmuci.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libbbfdm-api/legacy/dmuci.h b/libbbfdm-api/legacy/dmuci.h index d5e95f83..c88651bf 100644 --- a/libbbfdm-api/legacy/dmuci.h +++ b/libbbfdm-api/legacy/dmuci.h @@ -122,9 +122,9 @@ struct package_change section != NULL; \ section = _tmp, _tmp = (section) ? dmuci_walk_all_sections(package, section, GET_NEXT_SECTION) : NULL) -#define section_name(s) s ? (s)->e.name : "" -#define section_type(s) s ? (s)->type : "" -#define section_config(s) s ? (s)->package->e.name : "" +#define section_name(s) ((s) ? (s)->e.name : "") +#define section_type(s) ((s) ? (s)->type : "") +#define section_config(s) ((s) ? (s)->package->e.name : "" ) static inline void uci_list_insert(struct uci_list *list, struct uci_list *ptr) { @@ -371,4 +371,3 @@ bool dmuci_string_to_boolean(const char *value); bool dmuci_is_option_value_empty(struct uci_section *s, const char *option_name); #endif -