Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid ctype.h abuse: cast char to unsigned char first. #3152

Merged

Conversation

riastradh
Copy link
Contributor

fix #3151

@emanuele6
Copy link
Member

Basically the problem is that, if char is signed char on the target system, and the byte that is being checked is non-ascii e.g. 0x80-0xff, it will be sign extended to 0xffffffxx instead of being passed as 0x000000xx, and that is undefined behaviour.

It is wrong to call isspace(x) with a value of x>0x7f anyway because it would be checking a single byte instead of a character, but at least it is not undefined behaviour; let's merge this.

Thank you for the patch.

@emanuele6 emanuele6 added bug UB Fixes for undefined behaviours and removed bug labels Jul 11, 2024
@emanuele6 emanuele6 merged commit 2ee20ca into jqlang:master Jul 11, 2024
28 checks passed
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
UB Fixes for undefined behaviours
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undefined behaviour in use of <ctype.h> functions
2 participants