summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-04-23 20:29:15 +0200
committerLennart Poettering <lennart@poettering.net>2010-04-23 20:29:15 +0200
commitd4d0d4db9345170cc61a6b46ac9e11c5b8424b19 (patch)
tree1755e16893276b2ef1bdf02d3aa6bc195e66609b
parente558336f7b1c69c7335752642327dd1a737eeb15 (diff)
util: properly handle empty word suffixes/prefixes in startswith()/endswith()
-rw-r--r--util.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/util.c b/util.c
index 83e819a0cb..fd991cf807 100644
--- a/util.c
+++ b/util.c
@@ -114,6 +114,9 @@ bool endswith(const char *s, const char *postfix) {
sl = strlen(s);
pl = strlen(postfix);
+ if (pl == 0)
+ return true;
+
if (sl < pl)
return false;
@@ -129,6 +132,9 @@ bool startswith(const char *s, const char *prefix) {
sl = strlen(s);
pl = strlen(prefix);
+ if (pl == 0)
+ return true;
+
if (sl < pl)
return false;
@@ -147,11 +153,14 @@ bool first_word(const char *s, const char *word) {
if (sl < wl)
return false;
+ if (wl == 0)
+ return true;
+
if (memcmp(s, word, wl) != 0)
return false;
- return (s[wl] == 0 ||
- strchr(WHITESPACE, s[wl]));
+ return s[wl] == 0 ||
+ strchr(WHITESPACE, s[wl]);
}
int close_nointr(int fd) {