diff --git a/libc/src/string/strchr.cpp b/libc/src/string/strchr.cpp --- a/libc/src/string/strchr.cpp +++ b/libc/src/string/strchr.cpp @@ -14,12 +14,10 @@ // TODO: Look at performance benefits of comparing words. LLVM_LIBC_FUNCTION(char *, strchr, (const char *src, int c)) { - unsigned char *str = - const_cast(reinterpret_cast(src)); const unsigned char ch = c; - for (; *str && *str != ch; ++str) + for (; *src && static_cast(*src) != ch; ++src) ; - return *str == ch ? reinterpret_cast(str) : nullptr; + return *src == ch ? const_cast(src) : nullptr; } } // namespace __llvm_libc diff --git a/libc/src/string/strrchr.cpp b/libc/src/string/strrchr.cpp --- a/libc/src/string/strrchr.cpp +++ b/libc/src/string/strrchr.cpp @@ -13,12 +13,12 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(char *, strrchr, (const char *src, int c)) { - const char ch = c; + const unsigned char ch = c; char *last_occurrence = nullptr; - do { + for (; *src; ++src) { if (*src == ch) last_occurrence = const_cast(src); - } while (*src++); + } return last_occurrence; }