|
Boost : |
Subject: Re: [boost] [multiprecision review] Possible use of uninitialised value
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2012-06-14 08:27:43
The valgrind error I mentioned previously seems to be due to this code
at cpp_int.hpp line 967:
result.resize(x);
typename cpp_int_backend<MinBits, Signed,
Allocator>::const_limb_pointer pa = a.limbs();
typename cpp_int_backend<MinBits, Signed,
Allocator>::const_limb_pointer pb = b.limbs();
typename cpp_int_backend<MinBits, Signed, Allocator>::limb_pointer
pr = result.limbs();
bool swapped = false;
int c = a.compare_unsigned(b);
resize() doesn't zero-initialise the new storage. In this particular
case, a == result because the expression being evaluated is something
like result = result + other. So resizing result is also resizing a.
Hence the compare_unsigned looks at the limbs of a that have just been
added by the resize, which are undefined.
It appears that this could be fixed by zeroing the new limbs in
resize(), but that is unnecessary in other cases. Is it even correct
that a == result is possible in this code?
Regards, Phil.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk