From: Nathan McSween <nwmcsween@gmail.com>
To: musl@lists.openwall.com
Cc: Nathan McSween <nwmcsween@gmail.com>
Subject: [RFC PATCH 4/5] string: use strchrnul in strcasestr instead of bytewise iteration
Date: Sat, 15 Jul 2017 19:55:40 +0000 [thread overview]
Message-ID: <20170715195541.3136-5-nwmcsween@gmail.com> (raw)
In-Reply-To: <20170715195541.3136-1-nwmcsween@gmail.com>
---
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
next prev parent reply other threads:[~2017-07-15 19:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-15 19:55 [RFC PATCH 0/5] Add explicit_bzero, vectorize and 'normalize' various string functions Nathan McSween
2017-07-15 19:55 ` [RFC PATCH 1/5] string: vectorize various functions Nathan McSween
2017-07-15 19:55 ` [RFC PATCH 2/5] string: modify wordwise functions to match new style Nathan McSween
2017-07-15 19:55 ` [RFC PATCH 3/5] string: add strscpy and modify functions to use strscpy Nathan McSween
2017-07-15 19:55 ` Nathan McSween [this message]
2017-07-15 19:55 ` [RFC PATCH 5/5] string: add memsset a 'secure' memset and bsd explicit_bzero Nathan McSween
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170715195541.3136-5-nwmcsween@gmail.com \
--to=nwmcsween@gmail.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).