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

Added new method #17

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Added new method #17

wants to merge 7 commits into from

Conversation

rchateauneu
Copy link

No description provided.

@@ -120,7 +120,7 @@ namespace itoa_ljust {
uint32_t u = i;
if (i < 0) {
*p++ = '-';
u = -u;
u = (uint32_t)(-(int32_t)u);
Copy link
Contributor

Choose a reason for hiding this comment

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

Unary minus applied to a signed integer is undefined behavior for targets that use two's complement when the value is the most negative value (INT_MIN) representable in two's complement, it causes signed overflow. The compiler can assume this never happens. On clang/llvm this doesn't seem to cause a problem, but on gcc with -O3 optimization the compiler takes advantage of this assumption and generates code that gives the wrong answer (or causes segmentation fault).

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