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 34970e4141)
This commit is contained in:
Thomas Haller 2016-10-12 18:53:08 +02:00
parent cbfdb72db2
commit 7a8ed3fefd

View file

@ -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)