Bug Description
dynarray_insert() has the same double capacity increase bug as dynarray_push().
Location
src/modify.c lines 164-170
Current Code
if (array->length >= array->capacity) {
if (!dynarray_inc(array, array->capacity)) {
return false;
}
}
array->capacity *= 2; // ← Doubles capacity AGAIN after inc() already did!
Problem
Same as bug #4 in dynarray_push():
dynarray_inc() already increases capacity
- Then multiplication happens again
- Results in exponential memory waste
Expected Behavior
Should only resize once.
Proposed Fix
if (array->length >= array->capacity) {
size_t new_capacity = array->capacity * 2;
if (!dynarray_setSize(array, new_capacity)) {
return false;
}
}
// Remove the extra capacity *= 2 line
Related Issue
This is the same root cause as the push() capacity bug
Impact
- Severity: Medium
- Memory waste
- Less critical than push() because insert() is used less frequently
Bug Description
dynarray_insert()has the same double capacity increase bug asdynarray_push().Location
src/modify.clines 164-170Current Code
Problem
Same as bug #4 in
dynarray_push():dynarray_inc()already increases capacityExpected Behavior
Should only resize once.
Proposed Fix
Related Issue
This is the same root cause as the push() capacity bug
Impact