mirror of
https://github.com/boostorg/multiprecision.git
synced 2026-01-19 04:22:11 +00:00
Fix potentially uninitialized storage when parsing octal strings.
Fixes https://github.com/boostorg/multiprecision/issues/526
This commit is contained in:
@@ -1854,7 +1854,10 @@ public:
|
||||
{
|
||||
// If this is the most-significant-limb, we may need to allocate an extra one for the overflow:
|
||||
if (limb + 1 == newsize)
|
||||
{
|
||||
result.resize(static_cast<unsigned>(newsize + 1), static_cast<unsigned>(newsize + 1));
|
||||
result.limbs()[limb + 1] = 0;
|
||||
}
|
||||
if (result.size() > limb + 1)
|
||||
{
|
||||
result.limbs()[limb + 1] |= val;
|
||||
|
||||
@@ -1220,6 +1220,7 @@ test-suite misc :
|
||||
[ run git_issue_313.cpp ]
|
||||
[ run git_issue_488.cpp ]
|
||||
[ run git_issue_506.cpp ]
|
||||
[ run git_issue_526.cpp ]
|
||||
[ compile git_issue_98.cpp :
|
||||
[ check-target-builds ../config//has_float128 : <define>TEST_FLOAT128 <source>quadmath : ]
|
||||
[ check-target-builds ../config//has_gmp : <define>TEST_GMP <source>gmp : ]
|
||||
|
||||
18
test/git_issue_526.cpp
Normal file
18
test/git_issue_526.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2023 John Maddock. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/multiprecision/cpp_int.hpp>
|
||||
#include "test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost::multiprecision;
|
||||
const std::string v("00000000000000000000000052222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222");
|
||||
cpp_int V(v);
|
||||
std::string r = V.str(0, std::ios_base::oct | std::ios_base::showbase);
|
||||
BOOST_CHECK_EQUAL(r, v.substr(23));
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user