Opened 7 years ago
Closed 7 years ago
#11627 closed Bugs (fixed)
small_vector<T,n>::swap( ) appears to be broken
Reported by: | Owned by: | Ion Gaztañaga | |
---|---|---|---|
Milestone: | To Be Determined | Component: | container |
Version: | Boost 1.59.0 | Severity: | Problem |
Keywords: | Cc: |
Description
The small_vector class seems like it could be really useful! However, it seems to have a broken implementation of the swap( ) member function.
The first test case creates a small_vector<int,10> of size 2. Swapping fails to clear the vector that is swapped from.
bredelings@transposon:~/Devel/bali-phy/master$ g++ test.C -I boost/include/ -std=c++14 bredelings@transposon:~/Devel/bali-phy/master$ ./a.out v.size() = 2 w.size() = 0
swapping v and w ...
v.size() = 2 w.size() = 2
The second test case creates a small_vector<int,10> of size 11. Swapping seems to work, but apparently corrupts the heap:
bredelings@transposon:~/Devel/bali-phy/master$ g++ test2.C -I boost/include/ -std=c++14 bredelings@transposon:~/Devel/bali-phy/master$ ./a.out v.size() = 11 w.size() = 0
swapping v and w ...
v.size() = 0 w.size() = 11 * Error in `./a.out': munmap_chunk(): invalid pointer: 0x00007ffd88feb978 * Aborted
Attachments (2)
Change History (4)
by , 7 years ago
by , 7 years ago
comment:1 by , 7 years ago
It seems that when executing test2.C, the small_vector w is correctly destroyed, but v is incorrectly destroyed.
comment:2 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Thanks for the report. The swap code handling the non-usual pointer swap idiom was not deleting the final elements. Also, an argument passed to test is the storage is propagable had a copy-paste error.
Fixed in:
https://github.com/boostorg/container/commit/f1f97518d338c7f7351308aa1785ebae5f2ddde7
second test case