summaryrefslogtreecommitdiffstats
path: root/include/godot_cpp
diff options
context:
space:
mode:
authorDavid Snopek <dsnopek@gmail.com>2023-09-20 07:39:27 -0500
committerGitHub <noreply@github.com>2023-09-20 07:39:27 -0500
commita3dfbbde8592abe26a8521bec703d5068cda1db5 (patch)
treef1dd9e78b8ba21c128dcdd4e0563436e18700740 /include/godot_cpp
parentb1fd1b65fd2bfbeac9704c2716ed20bcb08d7107 (diff)
parent06ffc7e9522d749afb9489c9739538e562799a93 (diff)
downloadredot-cpp-a3dfbbde8592abe26a8521bec703d5068cda1db5.tar.gz
Merge pull request #1245 from AThousandShips/alloc_fix
Fix allocation size overflow check in `CowData`
Diffstat (limited to 'include/godot_cpp')
-rw-r--r--include/godot_cpp/templates/cowdata.hpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/include/godot_cpp/templates/cowdata.hpp b/include/godot_cpp/templates/cowdata.hpp
index 121351b..9b36538 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);