Skip to content

Commit

Permalink
fixed invalid copying of shared_ptr
Browse files Browse the repository at this point in the history
danmelamed committed Aug 14, 2016
1 parent a2c9c79 commit 77cb357
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vowpalwabbit/feature_group.h
Original file line number Diff line number Diff line change
@@ -326,7 +326,7 @@ struct features {
{ copy_array(values, src.values);
copy_array(indicies, src.indicies);
free_space_names(0);
copy_array(space_names, src.space_names);
copy_array_no_memcpy(space_names, src.space_names);
sum_feat_sq = src.sum_feat_sq;
}
};
7 changes: 7 additions & 0 deletions vowpalwabbit/v_array.h
Original file line number Diff line number Diff line change
@@ -168,6 +168,13 @@ template<class T> void copy_array(v_array<T>& dst, const v_array<T>& src)
push_many(dst, src._begin, src.size());
}

// use to copy arrays of types with non-trivial copy constructors, such as shared_ptr
template<class T> void copy_array_no_memcpy(v_array<T>& dst, const v_array<T>& src)
{ dst.erase();
for (T*item = src._begin; item != src._end; ++item)
dst.push_back(*item);
}

template<class T> void copy_array(v_array<T>& dst, const v_array<T>& src, T(*copy_item)(T&))
{ dst.erase();
for (T*item = src._begin; item != src._end; ++item)

0 comments on commit 77cb357

Please sign in to comment.