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

Fix bug in return value of strcmp/strncmp #12

Merged
merged 2 commits into from
Mar 20, 2024

Conversation

calc84maniac
Copy link
Contributor

Zilog's implementations of strcmp and strncmp oddly sign extend the difference of the two characters. This notably has the following problems:

  • The C standard specifies the characters should be compared as unsigned char. Zilog's behavior is fine if all characters are in the ASCII range and thus differ by no more than 127, but larger differences may be returned with the wrong sign.
  • This behavior causes strings not to have a total ordering - for example, 0x20 < 0x70 and 0x70 < 0xC0 but 0x20 > 0xC0.
  • This was fixed by TI in their OS implementation, so this causes behavior different than in CEdev programs.

I was able to fix this (which ends up with better performance in the difference calculation so it's a win-win), and while I was at it, I also optimized the strncmp loop a bit. I also improved a couple of the pseudo op replacements from earlier Zilog routine edits.

I should also note that on the CEdev side, I fixed the strncasecmp errors which had been reported earlier, and also added an implementation for strcasecmp, so that should be usable in AgDev.

Copy link
Collaborator

@astralaster astralaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not test it, but looks good.

@astralaster astralaster merged commit efcc00d into pcawte:main Mar 20, 2024
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