[libc-commits] [PATCH] D106901: [libc] add strncmp to strings
Siva Chandra via Phabricator via libc-commits
libc-commits at lists.llvm.org
Wed Jul 28 11:14:18 PDT 2021
sivachandra accepted this revision.
sivachandra added inline comments.
This revision is now accepted and ready to land.
================
Comment at: libc/src/string/strncmp.cpp:24
+ ;
+ return *reinterpret_cast<const unsigned char *>(left) -
+ *reinterpret_cast<const unsigned char *>(right);
----------------
michaelrj wrote:
> sivachandra wrote:
> > Just pointing out as I am not sure what is right here: casting to `unsigned char` can remove the potential sign and lead to -1 > 0. Even `strcmp` is set up this way so may be clean up both of them in a follow up patch.
> given that these are supposed to be strings, I would assume that `unsigned char` is correct. Testing with my system libc, it appears that this is what it does as well. I ran strncmp on the following char array: `[-1, 'a', '\0']` compared to `"abc"` with length 3 and got the value 158, which is 255 - 97 (`'a'` = 97).
Thanks for checking!
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D106901/new/
https://reviews.llvm.org/D106901
More information about the libc-commits
mailing list