aboutsummaryrefslogtreecommitdiffstats
path: root/devel/libzakalwe/files/patch-include_zakalwe_array.h
blob: 5890ddecd796c556f89b1ddb13946a0e582dce78 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
--- include/zakalwe/array.h.orig	2022-10-06 20:04:46 UTC
+++ include/zakalwe/array.h
@@ -13,7 +13,7 @@ extern "C" {
 extern "C" {
 #endif
 
-static inline void *z_array_util_double_if_needed(void *ptr,
+static inline void *z_array_util_double_if_needed(void **ptr,
 						  const size_t num_members,
 						  size_t *num_allocated,
 						  const size_t size)
@@ -24,10 +24,14 @@ static inline void *z_array_util_double_if_needed(void
 	if (!z_mul2_size_t(&new_num_allocated, *num_allocated, 2))
 		return NULL;
 	new_num_allocated = Z_MAX(new_num_allocated, 1);
-	ptr = reallocarray(ptr, new_num_allocated, size);
-	if (ptr != NULL)
-		*num_allocated = new_num_allocated;
-	return ptr;
+	// ptr = reallocarray(ptr, new_num_allocated, size);
+	void *new_ptr = realloc(*ptr, new_num_allocated * size);
+	if (new_ptr == NULL)
+		return NULL;
+
+	*ptr = new_ptr;
+	*num_allocated = new_num_allocated;
+	return new_ptr;
 }
 
 int _z_array_allocate(const size_t new_num_items,