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

Undefined behavior on INT_MIN #118

Open
eyalroz opened this issue Aug 2, 2021 · 1 comment
Open

Undefined behavior on INT_MIN #118

eyalroz opened this issue Aug 2, 2021 · 1 comment

Comments

@eyalroz
Copy link

eyalroz commented Aug 2, 2021

The library has undefined behavior in some cases, due to applying the unary negation operator indiscriminately. For example, when we print:

sprintf_(buffer, "%d", INT_MIN);

we internally have an int value variable with value INT_MIN, and then we take -value (or 0 - value). That's undefined! Not good.

eyalroz added a commit to eyalroz/printf that referenced this issue Aug 2, 2021
eyalroz added a commit to eyalroz/printf that referenced this issue Aug 2, 2021
* Added comment explaining how we "narrowly escape" undefined behavior with our `NTOA_ABS()` macro.
* Added checks for printing extremal values of the various signed and unsigned integer types, just in case.
@eyalroz
Copy link
Author

eyalroz commented Aug 2, 2021

... and luckily, this seems to be averted on the fork.

eyalroz added a commit to eyalroz/printf that referenced this issue Aug 3, 2021
* Added comment explaining how we "narrowly escape" undefined behavior with our `NTOA_ABS()` macro.
* Added checks for printing extremal values of the various signed and unsigned integer types, just in case.
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

No branches or pull requests

1 participant