Opened 8 years ago
Closed 8 years ago
#11148 closed Bugs (fixed)
attribute_value_set.size() is busted
| Reported by: | Chris Newbold | Owned by: | Andrey Semashev |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | log |
| Version: | Boost 1.57.0 | Severity: | Regression |
| Keywords: | Cc: |
Description
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.

Fixed in https://github.com/boostorg/log/commit/f74a7df2df0947da7927782424924d605f11c349. Thanks for reporting this.