Modify

Opened 3 years ago

Closed 3 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.

Attachments (0)

Change History (1)

comment:1 Changed 3 years ago by Andrey Semashev

Resolution: fixed
Status: newclosed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Andrey Semashev.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.