Skip to content

Commit

Permalink
Better size handling in List.operator *=
Browse files Browse the repository at this point in the history
  • Loading branch information
GrieferAtWork committed Nov 24, 2023
1 parent 58ad91f commit 516969a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/deemon/objects/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -3264,10 +3264,6 @@ list_inplace_mul(List **__restrict p_self,
size_t i, my_length, result_length, multiplier;
if (DeeObject_AsSize(other, &multiplier))
goto err;
if unlikely(!multiplier) {
DeeList_Clear((DeeObject *)me);
goto done;
}
if unlikely(multiplier == 1)
goto done;
again:
Expand All @@ -3279,6 +3275,17 @@ list_inplace_mul(List **__restrict p_self,
goto err;
}
elemv = me->l_list.ol_elemv;
if unlikely(result_length <= 0) {
/* Special case: list is being cleared. */
size_t elemc;
elemc = me->l_list.ol_elemc;
elemv = me->l_list.ol_elemv;
Dee_objectlist_init(&me->l_list);
DeeList_LockEndWrite(me);
Dee_Decrefv(elemv, elemc);
Dee_Free(elemv);
goto done;
}

/* Make sure sufficient memory has been allocated. */
if (result_length > DeeList_GetAlloc(me)) {
Expand Down

0 comments on commit 516969a

Please sign in to comment.