summaryrefslogtreecommitdiff
path: root/dlib
diff options
context:
space:
mode:
Diffstat (limited to 'dlib')
-rw-r--r--dlib/dlib.c26
1 files changed, 14 insertions, 12 deletions
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;
}