Przeglądaj źródła

Fix unsigned integer bug in LocalVector::erase

`erase()` calls `find()` to get the index of the element to remove, if
any.

https://github.com/godotengine/godot/blob/c2151e18135817c9f926a5a00341016ac77301d4/core/local_vector.h#L77-L81

`find()` returns a signed integer. In particular, it returns -1 if
no element is found. Since `erase()` converts this to an unsigned type, the
wrong element may be erroneously removed from the vector.

Other ways to fix this would involve changing function signatures, so
this seemed to be the least disruptive change.

Fixes #38884
Maganty Rushyendra 5 lat temu
rodzic
commit
4ef246f804
1 zmienionych plików z 1 dodań i 1 usunięć
  1. 1 1
      core/local_vector.h

+ 1 - 1
core/local_vector.h

@@ -75,7 +75,7 @@ public:
 	}
 	}
 
 
 	void erase(const T &p_val) {
 	void erase(const T &p_val) {
-		U idx = find(p_val);
+		int64_t idx = find(p_val);
 		if (idx >= 0) {
 		if (idx >= 0) {
 			remove(idx);
 			remove(idx);
 		}
 		}