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: | 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)
Change History (5)
by , 9 years ago
follow-up: 2 comment:1 by , 9 years ago
good point ... but can you upload a working test case? will have a look at the code this night ...
comment:2 by , 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 , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
test that demonstrates the bug