undefined behavior itoa
Johannes Hack <[email protected]> Thu, 12 Feb 2026 16:55:49 +0000
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
Hello,
I believe I have found undefined behavior in |newlib/libc/stdlib/itoa.c|
when handling |INT_MIN.|
Best regards
Johannes
```
diff --git a/newlib/libc/stdlib/itoa.c b/newlib/libc/stdlib/itoa.c
index 7a7daf0ce..9271ec443 100644
--- a/newlib/libc/stdlib/itoa.c
+++ b/newlib/libc/stdlib/itoa.c
@@ -49,7 +49,7 @@ __itoa (int value,
if ((base == 10) && (value < 0))
{
str[i++] = '-';
- uvalue = (unsigned)-value;
+ uvalue = -(unsigned)value;
}
else
uvalue = (unsigned)value;
```