Index: uspace/lib/c/generic/malloc.c
===================================================================
--- uspace/lib/c/generic/malloc.c	(revision 878736ecd7510fb045c3c70492af1800c2d3ec67)
+++ uspace/lib/c/generic/malloc.c	(revision 899bdfda27b53bba2ce96d32870c576201ab6ba8)
@@ -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
  *
