[hackers] [wmii] Fix strcasestr. || Kris Maglione

From: <hg_AT_suckless.org>
Date: Tue, 10 Aug 2010 09:46:09 +0000 (UTC)

changeset: 2776:4ecd918e7afa
tag: tip
user: Kris Maglione <kris_AT_suckless.org>
date: Tue Aug 10 05:46:00 2010 -0400
files: include/stuff/util.h lib/libstuff/util/strcasestr.c
description:
Fix strcasestr.

diff -r d811fa819bee -r 4ecd918e7afa include/stuff/util.h
--- a/include/stuff/util.h Sat Jul 31 19:11:45 2010 -0400
+++ b/include/stuff/util.h Tue Aug 10 05:46:00 2010 -0400
@@ -151,5 +151,5 @@
 VECTOR(long, long, l)
 VECTOR(Rectangle, rect, r)
 VECTOR(void*, ptr, p)
-#undef VECTOR
+#undef VECTOR
 
diff -r d811fa819bee -r 4ecd918e7afa lib/libstuff/util/strcasestr.c
--- a/lib/libstuff/util/strcasestr.c Sat Jul 31 19:11:45 2010 -0400
+++ b/lib/libstuff/util/strcasestr.c Tue Aug 10 05:46:00 2010 -0400
@@ -9,17 +9,17 @@
 /* TODO: Make this UTF-8 compliant. */
 char*
 strcasestr(const char *dst, const char *src) {
- int dc, sc;
- int len;
+ int len, dc, sc;
+
+ if(src[0] == '\0')
+ return (char*)(uintptr_t)dst;
 
         len = strlen(src) - 1;
- for(; (sc = *src) && *dst; src++) {
- sc = tolower(dc);
- for(; (dc = *dst); dst++) {
- dc = tolower(dc);
- if(sc == dc && !strncasecmp(dst+1, src+1, len))
- return (char*)(uintptr_t)dst;
- }
+ sc = tolower(src[0]);
+ for(; (dc = *dst); dst++) {
+ dc = tolower(dc);
+ if(sc == dc && (len == 0 || !strncasecmp(dst+1, src+1, len)))
+ return (char*)(uintptr_t)dst;
         }
         return nil;
 }
Received on Tue Aug 10 2010 - 11:46:09 CEST

This archive was generated by hypermail 2.2.0 : Tue Aug 10 2010 - 11:48:04 CEST