string: Gracefully handle NULL in str*eq() macros

This commit is contained in:
Tobias Brunner
2016-04-04 10:43:46 +02:00
parent 90c8cf6819
commit 85597f2983
2 changed files with 82 additions and 4 deletions
+4 -4
View File
@@ -27,7 +27,7 @@
*/
static inline bool streq(const char *x, const char *y)
{
return strcmp(x, y) == 0;
return (x == y) || (x && y && strcmp(x, y) == 0);
}
/**
@@ -35,7 +35,7 @@ static inline bool streq(const char *x, const char *y)
*/
static inline bool strneq(const char *x, const char *y, size_t len)
{
return strncmp(x, y, len) == 0;
return (x == y) || (x && y && strncmp(x, y, len) == 0);
}
/**
@@ -51,7 +51,7 @@ static inline bool strpfx(const char *x, const char *prefix)
*/
static inline bool strcaseeq(const char *x, const char *y)
{
return strcasecmp(x, y) == 0;
return (x == y) || (x && y && strcasecmp(x, y) == 0);
}
/**
@@ -59,7 +59,7 @@ static inline bool strcaseeq(const char *x, const char *y)
*/
static inline bool strncaseeq(const char *x, const char *y, size_t len)
{
return strncasecmp(x, y, len) == 0;
return (x == y) || (x && y && strncasecmp(x, y, len) == 0);
}
/**