https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97641
Jakub Jelinek changed:
What|Removed |Added
Status|UNCONFIRMED |RESOLVED
Resolution|---
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97641
--- Comment #7 from Dmitriy Ovdienko ---
If I change the body of the loop like this, it also works
```
while ('\x01' != *ptr)
{
result = result * 10 - '0' + *ptr++;
}
```
Looks like integer overflow happens on last iteration and compiler
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97641
--- Comment #6 from Dmitriy Ovdienko ---
This code does not work
```
#include
int Parse1(char const* ptr) noexcept
{
int result = 0;
while ('\x01' != *ptr)
{
result = result * 10 + *ptr++ - '0';
}
return result;
}
i
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97641
Dmitriy Ovdienko changed:
What|Removed |Added
Status|RESOLVED|UNCONFIRMED
Resolution|INVALI
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97641
--- Comment #4 from Dmitriy Ovdienko ---
It happens to 2147483646, 2147483647 and std::numeric_limits::min().
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97641
--- Comment #3 from Jakub Jelinek ---
Use -fsanitize=undefined to get it diagnosed at runtime. Although, that
routine doesn't handle even Parse1("2147483631\x01") etc. correctly.
Just use unsigned int result = 0;
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97641
Jakub Jelinek changed:
What|Removed |Added
Status|UNCONFIRMED |RESOLVED
Resolution|---
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97641
--- Comment #1 from Dmitriy Ovdienko ---
OS: Windows 10
Distribution: MSys2 (https://www.msys2.org/)
Version: (Rev4, Built by MSYS2 project) 10.2.0
I tried to reproduce this issue on https://gcc.godbolt.org/. gcc (trunk) is
also unable to compil