From 7a8ed3fefde9449da3d28a258e818b50ca25ed90 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 12 Oct 2016 18:53:08 +0200 Subject: [PATCH] shared: make nm_str_not_empty() inline function instead of macro It was a macro to pass on the non-const-ness of the argument, but that just doesn't make sense. That is a signature char *nm_str_not_empty (char *) does not make sense, because you cannot transfer ownership conditionally without additional checks to avoid a leak. Which makes this form is pointless. For example: char * foo (void) { char *s; s = _create_value (); return nm_str_not_empty (s); /* leaks "" */ } (cherry picked from commit 34970e4141ed5ac2bedce6a6be83bb28515bb96b) --- shared/nm-utils/nm-macros-internal.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index 9e9f5d8f3c..e30a50a5ce 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -260,13 +260,11 @@ _NM_IN_STRSET_streq (const char *x, const char *s) /*****************************************************************************/ -#define nm_str_not_empty(str) \ - ({ \ - /* implemented as macro to preserve constness */ \ - typeof (str) __str = (str); \ - _nm_unused const char *__str_type_check = __str; \ - ((__str && __str[0]) ? __str : ((char *) NULL)); \ - }) +static inline const char * +nm_str_not_empty (const char *str) +{ + return str && str[0] ? str : NULL; +} static inline char * nm_strdup_not_empty (const char *str)