You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Keyframe::AddPoint() fix: reallocation invalidates iterator
Points.push_back can (and will) cause reallocation, which invalidates the candidate iterator. Thus better use an (integer) index.
This commit is contained in:
@@ -75,9 +75,10 @@ void Keyframe::AddPoint(Point p) {
|
||||
// New point needs to be inserted before candidate; thus move
|
||||
// candidate and all following one to the right and insert new
|
||||
// point then where candidate was.
|
||||
Points.push_back(p); // Make space; could also be a dummy point.
|
||||
std::move_backward(candidate, end(Points) - 1, end(Points));
|
||||
*candidate = p;
|
||||
size_t const candidate_index = candidate - begin(Points);
|
||||
Points.push_back(p); // Make space; could also be a dummy point. INVALIDATES candidate!
|
||||
std::move_backward(begin(Points) + candidate_index, end(Points) - 1, end(Points));
|
||||
Points[candidate_index] = p;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user