Opened 9 years ago

Last modified 9 years ago

#8628 new Bugs

spsc_queue::pop(OutputIterator it) improperly works with random-access iterators if the read pointer is bigger than the write pointer (stored data consists of 2 blocks)

Reported by: Constantin Fishkin <constantin_fishkin@…> Owned by: timblechmann
Milestone: To Be Determined Component: lockfree
Version: Boost 1.53.0 Severity: Not Applicable
Keywords: spsc_queue Cc:

Description

spsc_queue::pop(OutputIterator it) method improperly works with random-access iterators if the queue's read pointer is bigger than the queue's write pointer (the queue's stored data consists of 2 blocks)

The following code will fill dst array improperly if the queue's read pointer is bigger than the queue's write pointer:

unsigned char* dst=new unsigned char[100];

count=q.pop(dst);

The bug caused by the code in spsc_queue.hpp:224:

std::copy(internal_buffer+read_index, internal_buffer+max_size, it);

std::copy(internal_buffer, internal_buffer+count1, it);

It will copy the second fragment starting from the same point it copied the first ftagment. The problem can be fixed as:

it=std::copy(internal_buffer+read_index, internal_buffer+max_size, it);

std::copy(internal_buffer, internal_buffer+count1, it);

Change History (1)

comment:1 by Constantin Fishkin <constantin_fishkin@…>, 9 years ago

Severity: ProblemNot Applicable

Duplication of #8629

Note: See TracTickets for help on using tickets.