mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-27 03:30:09 +01:00
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:
parent
cbfdb72db2
commit
7a8ed3fefd
1 changed files with 5 additions and 7 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue