[libc-commits] [PATCH] D110581: [libc][NFC] Make strchr and strrchr more consistent
Siva Chandra via Phabricator via libc-commits
libc-commits at lists.llvm.org
Mon Sep 27 22:29:25 PDT 2021
sivachandra added inline comments.
================
Comment at: libc/src/string/strchr.cpp:17
LLVM_LIBC_FUNCTION(char *, strchr, (const char *src, int c)) {
- unsigned char *str =
- const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(src));
const unsigned char ch = c;
+ for (; *src && static_cast<unsigned char>(*src) != ch; ++src)
----------------
I had added a comment here but Phabricator ignored it for some reason.
I had pointed out that the standard actually says we should compare with characters in `src` after converting `c` to `char`. So, make this `char` instead of `unsigned char`. You will not need a cast on line 18.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D110581/new/
https://reviews.llvm.org/D110581
More information about the libc-commits
mailing list