BUG: vnl_matrix move-assignment segfault #701
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the move-assignment
operator=
forvnl_matrix
(see PR #694) when both left-hand side and right-hand side objects manage their own memory, the right-hand side object should finally be invalidated with null data, zero size, andm_LetArrayManageMemory
set to a default value of true (not false). The system segfaults should a user attempt tostd::swap
two matrices.Set
m_LetArrayManageMemory
to true in move-assignmentoperator=
for bothvnl_matrix
andvnl_vector
. Add more swap tests, including native swap andstd::swap
for bothvnl_matrix
andvnl_vector
.More Details
During move-assignment,
vnl_matrix
wrongly resetm_LetArrayManageMemory
to false. This is an issue should a user attempt tostd:swap
two matrices (while users should prefer the nativevnl_matrix::swap
function,std::swap
should certainly not segfault).The C++11
std::swap
method is implemented as followsWhen using
std::swap
on avnl_matrix
, matrix t1 would be cleared after line 1 but withm_LetArrayManageMemory = false
. Line two would attempt to follow a code path for externally managed memory and the system would segfault.PR Checklist
🚫 Makes breaking changes to the vxl/core/* API that requires semantic versioning increase
🚫 Makes design changes to existing vxl/core* API that requires semantic versioning increase
🚫 Makes changes to the contributed directory API DOES NOT require semantic versioning increase
✔️ Adds tests and baseline comparison (quantitative).
🚫 Adds Documentation.