This is an archive of the discontinued LLVM Phabricator instance.

[libc][NFC] Make strchr and strrchr more consistent
ClosedPublic

Authored by michaelrj on Sep 27 2021, 1:25 PM.

Diff Detail

Event Timeline

michaelrj created this revision.Sep 27 2021, 1:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 27 2021, 1:25 PM
michaelrj requested review of this revision.Sep 27 2021, 1:25 PM
sivachandra added inline comments.Sep 27 2021, 10:26 PM
libc/src/string/strrchr.cpp
16

Same here - keep this char instead of unsigned char. If it is unsigned char, then you end up comparing singed and unsigned values on line 19.

sivachandra added inline comments.Sep 27 2021, 10:29 PM
libc/src/string/strchr.cpp
16–17

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.

michaelrj updated this revision to Diff 375616.Sep 28 2021, 9:49 AM
michaelrj marked 2 inline comments as done.

change to comparing signed chars

sivachandra accepted this revision.Sep 28 2021, 10:11 AM
This revision is now accepted and ready to land.Sep 28 2021, 10:11 AM
This revision was landed with ongoing or failed builds.Sep 28 2021, 10:42 AM
This revision was automatically updated to reflect the committed changes.