浏览代码

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 年之前
父节点
当前提交
4ef246f804
共有 1 个文件被更改,包括 1 次插入1 次删除
  1. 1 1
      core/local_vector.h

+ 1 - 1
core/local_vector.h

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