libc/string: Improve memchr() - scc - simple c99 compiler
 (HTM) git clone git://git.simple-cc.org/scc
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 391c2dacb748852e77bfe811556b145ecdda684b
 (DIR) parent bbb33960d11eacc45a1ea00d60bf46a39ae9693b
 (HTM) Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
       Date:   Tue, 25 Mar 2025 18:36:39 +0100
       
       libc/string: Improve memchr()
       
       No need to increment something to decrement it later.
       
       Diffstat:
         M src/libc/string/memchr.c            |       6 +++---
       
       1 file changed, 3 insertions(+), 3 deletions(-)
       ---
 (DIR) diff --git a/src/libc/string/memchr.c b/src/libc/string/memchr.c
       @@ -7,7 +7,7 @@ memchr(const void *s, int c, size_t n)
        {
                unsigned char *bp = (unsigned char *) s;
        
       -        while (n > 0 && *bp++ != c)
       -                --n;
       -        return (n == 0) ? NULL : bp-1;
       +        for ( ; n > 0 && *bp != c; n--)
       +                ++bp;
       +        return (n == 0) ? NULL : bp;
        }