mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-12-16 03:08:52 +08:00
fix: avoid overflow at postproc of the last loop
This commit is contained in:
@@ -80,13 +80,22 @@ parse_binary_integer(location& loc)
|
|||||||
integer retval(0), base(1);
|
integer retval(0), base(1);
|
||||||
for(auto i(str.rbegin()), e(str.rend()); i!=e; ++i)
|
for(auto i(str.rbegin()), e(str.rend()); i!=e; ++i)
|
||||||
{
|
{
|
||||||
|
assert(base != 0); // means overflow, checked in the above code
|
||||||
if(*i == '1')
|
if(*i == '1')
|
||||||
{
|
{
|
||||||
retval += base;
|
retval += base;
|
||||||
|
if(std::numeric_limits<integer>::max() / 2 < base)
|
||||||
|
{
|
||||||
|
base = 0;
|
||||||
|
}
|
||||||
base *= 2;
|
base *= 2;
|
||||||
}
|
}
|
||||||
else if(*i == '0')
|
else if(*i == '0')
|
||||||
{
|
{
|
||||||
|
if(std::numeric_limits<integer>::max() / 2 < base)
|
||||||
|
{
|
||||||
|
base = 0;
|
||||||
|
}
|
||||||
base *= 2;
|
base *= 2;
|
||||||
}
|
}
|
||||||
else if(*i == '_')
|
else if(*i == '_')
|
||||||
|
|||||||
Reference in New Issue
Block a user