-
Notifications
You must be signed in to change notification settings - Fork 82
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
base: master
Are you sure you want to change the base?
Added new method #17
Conversation
@@ -120,7 +120,7 @@ namespace itoa_ljust { | |||
uint32_t u = i; | |||
if (i < 0) { | |||
*p++ = '-'; | |||
u = -u; | |||
u = (uint32_t)(-(int32_t)u); |
There was a problem hiding this comment.
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).
No description provided.