I noticed that if find_first_wholeword() is called with word at the very
beginning of p, we will deref *(p - 1) to see if it is a word boundary.
Fix by considering p = p0 to be a word boundary.
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
}
}
-static const char *find_first_wholeword(const char *p, const char *word)
+static const char *find_first_wholeword(const char *p0, const char *word)
{
+ const char *p = p0;
+
if (!p)
return NULL;
while ((p = strstr(p, word)) != NULL) {
- if (is_word_sep(*(p-1)) && is_word_sep(p[strlen(word)]))
+ if ((p == p0 || is_word_sep(*(p-1))) &&
+ is_word_sep(p[strlen(word)]))
return p;
p++;
}