Subject: [Boost-bugs] [Boost C++ Libraries] #11148: attribute_value_set.size() is busted
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-03-27 20:08:52
#11148: attribute_value_set.size() is busted
------------------------------+------------------------
Reporter: cnewbold | Owner: andysem
Type: Bugs | Status: new
Milestone: To Be Determined | Component: log
Version: Boost 1.57.0 | Severity: Regression
Keywords: |
------------------------------+------------------------
The problem can be illustrated with some code like this:
{{{
using boost::log::attribute_value_set;
const attribute_value_set& values(record.attribute_values());
const boost::log::attribute_value_set::size_type count(
values.size());
for (attribute_value_set::value_type i : values)
{
...
}
}}}
Under some circumstances we see that the for loop iterates over more than
'count' attribute values.
The problem is in attribute_value_set::implementation::size(), which looks
like this:
{{{
size_type size()
{
freeze();
return (m_pEnd - m_pStorage);
}
}}}
This works correctly when the set does not contain more attributes than
fit in the pre-allocated block pointed to by m_pStorage. But, looking at
attribute_value_set::implementation::insert_node(), we see that once the
internal node storage is exhausted, additional nodes are allocated on-the-
fly and are not accounted for in the computation in size():
{{{
node* insert_node(key_type key, bucket& b, node* where, mapped_type data)
{
node* p;
if (m_pEnd != m_pEOS)
{
p = m_pEnd++;
new (p) node(key, data, false);
}
else
{
p = new node(key, data, true);
}
...
}}}
I have not looked, but this problem may also exist in other
attribute_value_set like containers.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/11148> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:18 UTC