#49687 [SC-Low] An underflow in `remove_item` function in `Uint64SetLib` Contract.
Previous#49690 [SC-Low] Integer Underflow in UInt64SetLib.pyNext#49938 [SC-Low] Underflow Revert in `remove_item` When Removing from an Empty Array
Was this helpful?
Was this helpful?
Was this helpful?
def remove_item(to_remove: UInt64, items: DynamicArray[ARC4UInt64]) -> Tuple[Bool, DynamicArray[ARC4UInt64]]:
`last_idx = items.length - 1`
for idx, item in uenumerate(items):
if item.native == to_remove:
# remove last item to replace the "to_remove" item or remove entirely if it's the match
last_item = items.pop()
if idx != last_idx:
items[idx] = last_item
# return with the item removed
return Bool(True), items.copy()
# if here then item is not present
return Bool(False), items.copy()if len(items) == 0:
return Bool(False), items.copy()
else:
for idx, item in uenumerate(items):
if item.native == to_remove:
# remove last item to replace the "to_remove" item or remove entirely if it's the match
last_item = items.pop()
if idx != last_idx:
items[idx] = last_item
# return with the item removed
return Bool(True), items.copy()