From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11734 Path: news.gmane.org!.POSTED!not-for-mail From: Nathan McSween Newsgroups: gmane.linux.lib.musl.general Subject: [RFC PATCH 4/5] string: use strchrnul in strcasestr instead of bytewise iteration Date: Sat, 15 Jul 2017 19:55:40 +0000 Message-ID: <20170715195541.3136-5-nwmcsween@gmail.com> References: <20170715195541.3136-1-nwmcsween@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1500148734 1361 195.159.176.226 (15 Jul 2017 19:58:54 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 15 Jul 2017 19:58:54 +0000 (UTC) Cc: Nathan McSween To: musl@lists.openwall.com Original-X-From: musl-return-11747-gllmg-musl=m.gmane.org@lists.openwall.com Sat Jul 15 21:58:50 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1dWTD5-00087Q-3C for gllmg-musl@m.gmane.org; Sat, 15 Jul 2017 21:58:39 +0200 Original-Received: (qmail 3622 invoked by uid 550); 15 Jul 2017 19:58:30 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 3404 invoked from network); 15 Jul 2017 19:58:25 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=b+wZZ0uh1Z5GwuzD1AaomtJagieSAlo1rQuOGyn89Aw=; b=Dy1PlR5NjixemyhNqagZOt4gfQhLr1SgMyfqXGxT/Tf53c5ICRMkLqWV73lFA1bGd4 JHYl3tY4ruOS2kQzEni0DELeq6WDOYOEEyYdsPZDIx5E8hXu304J1xDo/o5CzTStbOWe KJR1yfz4+vMVAIxwj/RSuaViX4aY11qKSnStcK24+TDYwTjxs1ngGDhFr9x1b8q7cwvH qha3iApvw5UtqZh3gRaAhQVkqBf+ApHKeDF/DuFcOay33edOkSGVXYCHfFVDMk9hXstJ FDbh1igkYo/M4UZCaCNgHWsE3mTgMBRCVoq9TSsYvJAIg21bfsGipH5A1jJFT76tZsbX dGxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=b+wZZ0uh1Z5GwuzD1AaomtJagieSAlo1rQuOGyn89Aw=; b=anhX27atnhSaDlw95ej/WHh9FAZRgjqn5AhkW51/mruDPIqTqoFUaumSN9McunVu5v QQ1gASWfqNT4H8G5FZiYf7Z7P9NEyPSdebhzGWC/ARXoAZQnrBMG7qBs8lVq/5MbBweY apAqJblEF//EBkWmFDruUU+57ZhVT5g+zcsSBRCAOjg+0NQ5cLCigCtw5lsy3vcpRNJq NxqbV7N1NWpuIFglhgHKRFNUI8DtJjpwYaxnOHqQFD4rDAnEzBpDRErsBncW/b0eJF4+ VyRmAy+WObcu86r6WIdc5k04Gs0t69VwcnrSo753wRGOfz6cfR4VtqhajGHM9j8pioch O4+g== X-Gm-Message-State: AIVw111/U3K7iNxH4Yppm6jseDGjNY/0KV67ZRj4O2SKAchykQj7DpW/ vQxzVzsnoxvXA3Mq X-Received: by 10.98.245.207 with SMTP id b76mr11463040pfm.113.1500148693834; Sat, 15 Jul 2017 12:58:13 -0700 (PDT) X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170715195541.3136-1-nwmcsween@gmail.com> Xref: news.gmane.org gmane.linux.lib.musl.general:11734 Archived-At: --- 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