Index: common/include/stdlib.h
===================================================================
--- common/include/stdlib.h	(revision 2ee6351d833181079f0e8f8c240f5ac2ade332a3)
+++ common/include/stdlib.h	(revision dd50aa1911e36b82569a97729165ef1d797d3cd1)
@@ -122,4 +122,7 @@
     __attribute__((malloc));
 
+extern void *reallocarray(void *ptr, size_t nelem, size_t elsize)
+    __attribute__((warn_unused_result));
+
 __HELENOS_DECLS_END;
 #endif
Index: kernel/generic/src/mm/malloc.c
===================================================================
--- kernel/generic/src/mm/malloc.c	(revision 2ee6351d833181079f0e8f8c240f5ac2ade332a3)
+++ kernel/generic/src/mm/malloc.c	(revision dd50aa1911e36b82569a97729165ef1d797d3cd1)
@@ -211,4 +211,7 @@
 void *realloc(void *old_obj, size_t new_size)
 {
+	if (new_size == 0)
+		new_size = 1;
+
 	if (!old_obj)
 		return malloc(new_size);
Index: uspace/lib/c/generic/malloc.c
===================================================================
--- uspace/lib/c/generic/malloc.c	(revision 2ee6351d833181079f0e8f8c240f5ac2ade332a3)
+++ uspace/lib/c/generic/malloc.c	(revision dd50aa1911e36b82569a97729165ef1d797d3cd1)
@@ -38,4 +38,5 @@
 #include <stdbool.h>
 #include <stddef.h>
+#include <stdio.h>
 #include <as.h>
 #include <align.h>
@@ -725,10 +726,13 @@
  *
  */
-static void *malloc_internal(const size_t size, const size_t align)
+static void *malloc_internal(size_t size, size_t align)
 {
 	malloc_assert(first_heap_area != NULL);
 
+	if (size == 0)
+		size = 1;
+
 	if (align == 0)
-		return NULL;
+		align = BASE_ALIGN;
 
 	size_t falign = lcm(align, BASE_ALIGN);
@@ -821,9 +825,9 @@
  *
  */
-void *realloc(void *const addr, const size_t size)
+void *realloc(void *const addr, size_t size)
 {
 	if (size == 0) {
-		free(addr);
-		return NULL;
+		fprintf(stderr, "realloc() called with size 0\n");
+		size = 1;
 	}
 
@@ -930,4 +934,23 @@
 }
 
+/** Reallocate memory for an array
+ *
+ * Same as realloc(ptr, nelem * elsize), except the multiplication is checked
+ * for numerical overflow. Borrowed from POSIX 2024.
+ *
+ * @param ptr
+ * @param nelem
+ * @param elsize
+ *
+ * @return Reallocated memory or NULL.
+ */
+void *reallocarray(void *ptr, size_t nelem, size_t elsize)
+{
+	if (nelem > SIZE_MAX / elsize)
+		return NULL;
+
+	return realloc(ptr, nelem * elsize);
+}
+
 /** Free a memory block
  *
