Skip to content

Commit 006eaa7

Browse files
authored
Ensure dst_vec is initialized after init_copy() (#2170)
1 parent cf56954 commit 006eaa7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/common/src/mlib/vec.th

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ fn(init_copy(VecName *dst_vec, VecName const *src_vec)) mlib_noexcept
396396
if (!fn(reserve(&tmp, src_vec->size))) {
397397
// We failed to reserve capacity in the new vector
398398
fn(destroy(&tmp));
399+
// Always leave `dst_vec` in an initialized state.
400+
*dst_vec = (VecName){NULL, 0, 0};
399401
return false;
400402
}
401403
// Copy everything into the destination element-by-element
@@ -412,6 +414,8 @@ fn(init_copy(VecName *dst_vec, VecName const *src_vec)) mlib_noexcept
412414
if (!VecCopyElement((out_iter), (in_iter))) {
413415
// Failed copying here. Undo everything by destroying the temporary
414416
fn(destroy(&tmp));
417+
// Always leave `dst_vec` in an initialized state.
418+
*dst_vec = (VecName){NULL, 0, 0};
415419
return false;
416420
}
417421
// Update the size of the temporary vec to record that it is holding the new

0 commit comments

Comments
 (0)