VecInitClone
Description
Reinitialize vd as a deep clone of vs. Any current contents of vd are first deinitialized. The destination adopts vs’s copy_init / copy_deinit / allocator configuration, then all elements are deep-copied.
Parameters
| Name | Direction | Description |
|---|---|---|
vd |
out | Destination vector. Must be initialized; its current contents are released before cloning. |
vs |
in | Source vector. |
Success
Returns true. vd now holds a deep copy of every element of vs, has the same length, and carries vs’s copy_init / copy_deinit / allocator configuration. The prior contents of vd were released before the clone began.
Failure
Returns false on allocation failure during the clone. vd is left in a valid but partially-populated state (the prior contents are gone). Callers should treat vd as opaque on failure and call VecDeinit(vd) before reuse.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Insert.h:1073:
#define VecMustInitClone(vd, vs) \
do { \
if (!VecInitClone((vd), (vs))) { \
LOG_FATAL("VecMustInitClone failed"); \
} \- In
Insert.h:844:
/// TAGS: Str, Clone, Init, DeepCopy
///
#define StrInitClone(strd, strs) VecInitClone((strd), (strs))
///
- In
VecInt.c:397:
}
VecInitClone(vec, &temp);
VecDeinit(&temp); // Clean up temp to prevent memory leak
- In
VecCharPtr.c:485:
}
VecInitClone(vec, &temp);
VecDeinit(&temp);- In
VecStr.c:463:
}
VecInitClone(vec, &temp);
VecDeinit(&temp);- In
Complex.c:914:
IntVec dst = VecInit(&local);
VecInitClone(&dst, &src);
// Under the mutant src->length != 0 returns true immediately and dst is
- In
Complex.c:940:
IntVec dst = VecInit(&local);
VecInitClone(&dst, &src);
// Real: dst has all 3 elements starting at index 0. Mutant (init 42):
- In
Complex.c:966:
IntVec dst = VecInit(&local);
VecInitClone(&dst, &src);
// Mutant (i >= length): 0 >= 3 is false, loop never runs, dst empty.
- In
Complex.c:991:
IntVec dst = VecInit(&local);
VecInitClone(&dst, &src);
// Real: dst length 3, all values present. Mutant (i--): dst length 1.
- In
Complex.c:1016:
IntVec dst = VecInit(&local);
bool cloned = VecInitClone(&dst, &src);
// Real: cloned true, dst length 3. Mutant: insert expression is 0 so the
- In
Access.c:339:
U32Vec dst = VecInit(&alloc);
VecInitClone(&dst, &src);
// Real: dst == {10,20,30,40}. Mutant (constant offset): every source read
Last updated on