|
Message-Id: <20170715195541.3136-5-nwmcsween@gmail.com> Date: Sat, 15 Jul 2017 19:55:40 +0000 From: Nathan McSween <nwmcsween@...il.com> To: musl@...ts.openwall.com Cc: Nathan McSween <nwmcsween@...il.com> Subject: [RFC PATCH 4/5] string: use strchrnul in strcasestr instead of bytewise iteration --- src/string/strcasestr.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/string/strcasestr.c b/src/string/strcasestr.c index af109f36..090b78fd 100644 --- a/src/string/strcasestr.c +++ b/src/string/strcasestr.c @@ -3,7 +3,13 @@ char *strcasestr(const char *h, const char *n) { - size_t l = strlen(n); - for (; *h; h++) if (!strncasecmp(h, n, l)) return (char *)h; - return 0; + const size_t nl= strlen(n); + + h = strchrnul(h, *n); + + if (!*n) return (char *)h; + + for (; *h && strncasecmp(h, n, nl); h = strchrnul(h + 1, *n)); + + return *h ? (char *)h : 0; } -- 2.13.2
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.