mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-08 06:38:11 +02:00
shared: gracefully accept %NULL strings for NM_STR_HAS_PREFIX() and NM_STR_HAS_SUFFIX()
In case it wasn't obvious to a caller, allow %NULL as valid string argument. Just be a bit more forgiving and fault-tolerant.
This commit is contained in:
parent
c045267837
commit
fe52a9467b
1 changed files with 9 additions and 4 deletions
|
|
@ -906,14 +906,19 @@ nm_streq0 (const char *s1, const char *s2)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NM_STR_HAS_PREFIX(str, prefix) \
|
#define NM_STR_HAS_PREFIX(str, prefix) \
|
||||||
(strncmp ((str), ""prefix"", NM_STRLEN (prefix)) == 0)
|
({ \
|
||||||
|
const char *const _str = (str); \
|
||||||
|
\
|
||||||
|
_str && (strncmp ((str), ""prefix"", NM_STRLEN (prefix)) == 0); \
|
||||||
|
})
|
||||||
|
|
||||||
#define NM_STR_HAS_SUFFIX(str, suffix) \
|
#define NM_STR_HAS_SUFFIX(str, suffix) \
|
||||||
({ \
|
({ \
|
||||||
const char *_str = (str); \
|
const char *_str; \
|
||||||
gsize _l = strlen (_str); \
|
gsize _l; \
|
||||||
\
|
\
|
||||||
( (_l >= NM_STRLEN (suffix)) \
|
( (_str = (str)) \
|
||||||
|
&& ((_l = strlen (_str)) >= NM_STRLEN (suffix)) \
|
||||||
&& (memcmp (&_str[_l - NM_STRLEN (suffix)], \
|
&& (memcmp (&_str[_l - NM_STRLEN (suffix)], \
|
||||||
""suffix"", \
|
""suffix"", \
|
||||||
NM_STRLEN (suffix)) == 0)); \
|
NM_STRLEN (suffix)) == 0)); \
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue