This is an archive of the discontinued LLVM Phabricator instance.

[libc] clean up ctype negative handling
ClosedPublic

Authored by michaelrj on Apr 7 2023, 2:05 PM.

Details

Summary

The ctype functions will sometimes be passed negative numbers, such as
EOF. Some of the previous implementations didn't handle these properly.
Additionally, the tests did not check any negative numbers. These
problems have been fixed.

This patch fixes https://github.com/llvm/llvm-project/issues/62000

Diff Detail

Event Timeline

michaelrj created this revision.Apr 7 2023, 2:05 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 7 2023, 2:05 PM
michaelrj requested review of this revision.Apr 7 2023, 2:05 PM
lntue accepted this revision.Apr 7 2023, 10:08 PM
This revision is now accepted and ready to land.Apr 7 2023, 10:08 PM
This revision was automatically updated to reflect the committed changes.
rillig added a subscriber: rillig.Apr 10 2023, 4:11 PM

The implementation of the <ctype.h> functions only needs to accept EOF or a value representable as unsigned char. Testing the functions with other negative numbers may invoke undefined behavior, as the implementation need not handle these numbers. Therefore, the words "such as" from the commit message sound misleading to me.