From e47158fd9023eec4dd5e852f33f327901a5a6632 Mon Sep 17 00:00:00 2001 From: corvid Date: Tue, 28 Jul 2009 16:32:27 +0000 Subject: dStristr check for NULL args --- dlib/dlib.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'dlib') diff --git a/dlib/dlib.c b/dlib/dlib.c index d5383903..b87d0ce1 100644 --- a/dlib/dlib.c +++ b/dlib/dlib.c @@ -169,18 +169,20 @@ char *dStrsep(char **orig, const char *delim) char *dStristr(const char *haystack, const char *needle) { int i, j; - - for (i = 0, j = 0; haystack[i] && needle[j]; ++i) - if (tolower(haystack[i]) == tolower(needle[j])) { - ++j; - } else if (j) { - i -= j; - j = 0; - } - - if (!needle[j]) /* Got all */ - return (char *)(haystack + i - j); - return NULL; + char *ret = NULL; + + if (haystack && needle) { + for (i = 0, j = 0; haystack[i] && needle[j]; ++i) + if (tolower(haystack[i]) == tolower(needle[j])) { + ++j; + } else if (j) { + i -= j; + j = 0; + } + if (!needle[j]) /* Got all */ + ret = (char *)(haystack + i - j); + } + return ret; } -- cgit v1.2.3