Skip to content

Conversation

pinotree
Copy link
Contributor

@pinotree pinotree commented Nov 17, 2021

In case 'char' is unsigned (which happens on some architectures), then
checks like str[i] > 0 will always be true (for non-NULL characters,
of course). Since we are interested to check only for the values <= 127,
then change the check to cast the char to unsigned, so we can always
check that the value is lower than 0x80 (128).

@evanmiller
Copy link
Contributor

Can we simplify this logic with (unsigned char)str[i] < 0x80?

In case 'char' is unsigned (which happens on some architectures), then
checks like 'str[i] > 0' will always be true (for non-NULL characters,
of course). Since we are interested to check only for the values <= 127,
then change the check to cast the char to unsigned, so we can always
check that the value is lower than 0x80 (128).
@pinotree
Copy link
Contributor Author

Can we simplify this logic with (unsigned char)str[i] < 0x80?

Oh indeed; apparently I complicated this overlooking the easy solution; thanks!

@evanmiller evanmiller changed the base branch from master to dev November 17, 2021 13:04
@evanmiller evanmiller merged commit 53c027c into WizardMac:dev Nov 17, 2021
@pinotree pinotree deleted the unsigned-char-unicode-check branch November 17, 2021 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants