[libc-commits] [libc] 1b35c4f - [libc] [obvious] In strrchr, remove cast to unsigned char before

via libc-commits libc-commits at lists.llvm.org
Fri Jul 31 17:16:04 PDT 2020


Author: cgyurgyik
Date: 2020-07-31T20:14:34-04:00
New Revision: 1b35c4fed29d6136ce241a692ce0a7165e59bf81

URL: https://github.com/llvm/llvm-project/commit/1b35c4fed29d6136ce241a692ce0a7165e59bf81
DIFF: https://github.com/llvm/llvm-project/commit/1b35c4fed29d6136ce241a692ce0a7165e59bf81.diff

LOG: [libc] [obvious] In strrchr, remove cast to unsigned char before
comparison.

Added: 
    

Modified: 
    libc/src/string/strrchr.cpp

Removed: 
    


################################################################################
diff  --git a/libc/src/string/strrchr.cpp b/libc/src/string/strrchr.cpp
index 28716c28a266..374a802fbb9e 100644
--- a/libc/src/string/strrchr.cpp
+++ b/libc/src/string/strrchr.cpp
@@ -13,16 +13,13 @@
 namespace __llvm_libc {
 
 char *LLVM_LIBC_ENTRYPOINT(strrchr)(const char *src, int c) {
-  unsigned char *str =
-      const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(src));
-  const unsigned char ch = c;
-
-  unsigned char *last_occurrence = nullptr;
+  const char ch = c;
+  char *last_occurrence = nullptr;
   do {
-    if (*str == ch)
-      last_occurrence = str;
-  } while (*str++);
-  return reinterpret_cast<char *>(last_occurrence);
+    if (*src == ch)
+      last_occurrence = const_cast<char *>(src);
+  } while (*src++);
+  return last_occurrence;
 }
 
 } // namespace __llvm_libc


        


More information about the libc-commits mailing list