Просмотр исходного кода

fix(datastructures): handle null index in remove_first_where

Add null check before calling remove_internal to prevent errors when
no element matches the predicate.
Billy Barrow 1 день назад
Родитель
Сommit
7446b2204e
1 измененных файлов с 4 добавлено и 1 удалено
  1. 4 1
      src/lib/DataStructures/Vector.vala

+ 4 - 1
src/lib/DataStructures/Vector.vala

@@ -230,7 +230,10 @@ namespace Invercargill.DataStructures {
         }
         }
 
 
         public void remove_first_where(Invercargill.PredicateDelegate<T> predicate) {
         public void remove_first_where(Invercargill.PredicateDelegate<T> predicate) {
-            remove_internal(first_index_of(predicate));
+            var index = first_index_of(predicate);
+            if (index != null) {
+                remove_internal(index);
+            }
         }
         }
 
 
         public void remove_all_where(Invercargill.PredicateDelegate<T> predicate) {
         public void remove_all_where(Invercargill.PredicateDelegate<T> predicate) {