diff options
author | A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> | 2023-09-19 15:20:02 +0200 |
---|---|---|
committer | A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> | 2023-09-19 16:14:00 +0200 |
commit | 06ffc7e9522d749afb9489c9739538e562799a93 (patch) | |
tree | 090b61eb5732ec11ab11d58d67217d4260f579a6 /include/godot_cpp | |
parent | 73500966aef159076831efb6141a6b36e102d69e (diff) | |
download | redot-cpp-06ffc7e9522d749afb9489c9739538e562799a93.tar.gz |
Fix allocation size overflow check in `CowData`
Diffstat (limited to 'include/godot_cpp')
-rw-r--r-- | include/godot_cpp/templates/cowdata.hpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/include/godot_cpp/templates/cowdata.hpp b/include/godot_cpp/templates/cowdata.hpp index d3ea982..b5c6e0b 100644 --- a/include/godot_cpp/templates/cowdata.hpp +++ b/include/godot_cpp/templates/cowdata.hpp @@ -102,6 +102,10 @@ private: } _FORCE_INLINE_ bool _get_alloc_size_checked(size_t p_elements, size_t *out) const { + if (unlikely(p_elements == 0)) { + *out = 0; + return true; + } #if defined(__GNUC__) size_t o; size_t p; @@ -113,13 +117,12 @@ private: if (__builtin_add_overflow(o, static_cast<size_t>(32), &p)) { return false; // No longer allocated here. } - return true; #else // Speed is more important than correctness here, do the operations unchecked // and hope for the best. *out = _get_alloc_size(p_elements); - return true; #endif + return *out; } void _unref(void *p_data); |