Opened 9 years ago

Closed 9 years ago

#8629 closed Bugs (fixed)

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: Problem
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);

Attachments (2)

main.cpp (114 bytes ) - added by Constantin Fishkin <constantin_fishkin@…> 9 years ago.
test that demonstrates the bug
test.cpp (1.7 KB ) - added by Constantin Fishkin <constantin_fishkin@…> 9 years ago.
this time proper file

Download all attachments as: .zip

Change History (5)

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

Attachment: main.cpp added

test that demonstrates the bug

comment:1 by timblechmann, 9 years ago

good point ... but can you upload a working test case? will have a look at the code this night ...

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

Attachment: test.cpp added

this time proper file

in reply to:  1 comment:2 by Constantin Fishkin <constantin_fishkin@…>, 9 years ago

Replying to timblechmann:

good point ... but can you upload a working test case? will have a look at the code this night ...

Oops, sorry. Please have a look at test.cpp

comment:3 by timblechmann, 9 years ago

Resolution: fixed
Status: newclosed

(In [84571]) lockfree: spsc-queue - correct dequeue to output iterator

fixes #8629

Signed-off-by: Tim Blechmann <tim@…>

Note: See TracTickets for help on using tickets.