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

tinystdio:fixing hexadecimal string conversion #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

HanaMAshour
Copy link
Collaborator

The hexadecimal string with decimal points was handled in a wrong way when it was passed to these functions strod(), strtof() and strtold(). The exp variable was only handled when the exp_match is equal to 'p' or 'e', so when any other hexadecimal string with no e or p format specifiers is passed, wrong results returned. therefore the change was made so the exp is handled correctly in all cases not only when p or e are passed as format specifiers.

added a new testing value in the file test-strtod.c to test the mentioned case above.
line 59 in the file test-strtod.c, shows that without this change there is an issue if the hexadecimal input has no e or p format specifiers.

added an extra else if condition to make sure that the exp is calulated
correctly when the exp_match is 'e'

The hexadecimal string with decimal points was handled in a wrong way when it
was passed to these functions strod(), strtof() and strtold().
The exp variable was only handled when the exp_match is equal to 'p' or 'e',
so when any other hexadecimal string with no e or p format specifiers is passed,
wrong results returned. therefore the change was made so the exp is handled
correctly in all cases not only when p or e are passed as format specifiers.

added a new testing value in the file test-strtod.c to test the mentioned case above.

Signed-off-by: Hana Ashour <[email protected]>
@keith-packard
Copy link
Collaborator

Nice bug report! I've simplified your proposed patch to perform the hex value adjustment entirely so that it was applied for all cases where there wasn't a complete exponent -- "0x0.1p" for instance. I'll see about adjusting the test so we can check those cases as well. Check out https://github.com/picolibc/picolibc/tree/keithp_hex_conversion and see what you think.

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