@@ -102,6 +102,10 @@ class CowData {
102102}
103103
104104_FORCE_INLINE_ bool  _get_alloc_size_checked (size_t  p_elements, size_t  *out) const  {
105+ if  (unlikely (p_elements == 0 )) {
106+ *out = 0 ;
107+ return  true ;
108+ }
105109#if  defined(__GNUC__)
106110size_t  o;
107111size_t  p;
@@ -113,13 +117,12 @@ class CowData {
113117if  (__builtin_add_overflow (o, static_cast <size_t >(32 ), &p)) {
114118return  false ; //  No longer allocated here.
115119}
116- return  true ;
117120#else 
118121//  Speed is more important than correctness here, do the operations unchecked
119122//  and hope for the best.
120123*out = _get_alloc_size (p_elements);
121- return  true ;
122124#endif 
125+ return  *out;
123126}
124127
125128void  _unref (void  *p_data);
@@ -294,15 +297,15 @@ Error CowData<T>::resize(int p_size) {
294297if  (current_size == 0 ) {
295298//  alloc from scratch
296299uint32_t  *ptr = (uint32_t  *)Memory::alloc_static (alloc_size, true );
297- ERR_FAIL_COND_V (! ptr, ERR_OUT_OF_MEMORY);
300+ ERR_FAIL_NULL_V ( ptr, ERR_OUT_OF_MEMORY);
298301*(ptr - 1 ) = 0 ; //  size, currently none
299302new  (ptr - 2 ) SafeNumeric<uint32_t >(1 ); //  refcount
300303
301304_ptr = (T *)ptr;
302305
303306} else  {
304307uint32_t  *_ptrnew = (uint32_t  *)Memory::realloc_static (_ptr, alloc_size, true );
305- ERR_FAIL_COND_V (! _ptrnew, ERR_OUT_OF_MEMORY);
308+ ERR_FAIL_NULL_V ( _ptrnew, ERR_OUT_OF_MEMORY);
306309new  (_ptrnew - 2 ) SafeNumeric<uint32_t >(rc); //  refcount
307310
308311_ptr = (T *)(_ptrnew);
@@ -332,7 +335,7 @@ Error CowData<T>::resize(int p_size) {
332335
333336if  (alloc_size != current_alloc_size) {
334337uint32_t  *_ptrnew = (uint32_t  *)Memory::realloc_static (_ptr, alloc_size, true );
335- ERR_FAIL_COND_V (! _ptrnew, ERR_OUT_OF_MEMORY);
338+ ERR_FAIL_NULL_V ( _ptrnew, ERR_OUT_OF_MEMORY);
336339new  (_ptrnew - 2 ) SafeNumeric<uint32_t >(rc); //  refcount
337340
338341_ptr = (T *)(_ptrnew);
0 commit comments