Repository navigation
Fix Zonotope copy/move operations and add regression tests - #526
Open
divyani-22 wants to merge 1 commit into
Open
divyani-22 wants to merge 1 commit into
divyani-22 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #511
What was wrong
Zonotope(include/convex_bodies/zpolytope.h) maintained five raw scratch arrays (conv_comb,row_mem,row,colno,colno_mem) handed to the lp_solve based oracles. Its hand-written copy and move operations suffered from the exact defects previously diagnosed in #503 and fixed forVPolytopein #519:operator=):copy_array(T* source, T* result, size_t count)passedresultby value. It freed the member's buffer (delete [] result;) but never stored the allocated copy back intothis. The member pointers dangled, causing heap-use-after-free and double-free on destruction.colno = other.colno; colno = nullptr;andcolno_mem = other.colno_mem; colno_mem = nullptr;nulledthis->colnoandthis->colno_memrather than the moved-from object's members. The moved-to object was left with null pointers, crashing on subsequent oracle calls. Additionally, move assignment did not free existing buffers before reassigning pointers._inner_ballwas dropped across copy and move operations.The Fix
mutable std::vector<REAL>(conv_comb,row_mem,row) andmutable std::vector<int>(colno,colno_mem)..data().*(conv_comb + j)pointer arithmetic with direct index accessconv_comb[j]._inner_ball.Tests
Added
test/zonotope_test.cpp(registered aszonotope_copy_movein CTest) mirroringvpolytope_test.cpp:_inner_ball.line_intersectandis_in) on each result.