Display and control your Android device
Add compat for reallocarray()
Romain Vimont6dceb328173e
diff --git a/app/meson.build b/app/meson.buildindex 8be917e9..7bdd288d 100644--- a/app/meson.build+++ b/app/meson.build@@ -169,6 +169,7 @@ check_functions = ['vasprintf','nrand48','jrand48',+ 'reallocarray',]foreach f : check_functionsdiff --git a/app/src/compat.c b/app/src/compat.cindex bb0152aa..785f843c 100644--- a/app/src/compat.c+++ b/app/src/compat.c@@ -3,6 +3,9 @@#include "config.h"#include <assert.h>+#ifndef HAVE_REALLOCARRAY+# include <errno.h>+#endif#include <stdlib.h>#include <stdio.h>#include <stdarg.h>@@ -93,5 +96,15 @@ long jrand48(unsigned short xsubi[3]) {return v.i;}#endif+#endif+#ifndef HAVE_REALLOCARRAY+void *reallocarray(void *ptr, size_t nmemb, size_t size) {+ size_t bytes;+ if (__builtin_mul_overflow(nmemb, size, &bytes)) {+ errno = ENOMEM;+ return NULL;+ }+ return realloc(ptr, bytes);+}#endifdiff --git a/app/src/compat.h b/app/src/compat.hindex 857623e6..ea44437d 100644--- a/app/src/compat.h+++ b/app/src/compat.h@@ -67,4 +67,8 @@ long nrand48(unsigned short xsubi[3]);long jrand48(unsigned short xsubi[3]);#endif+#ifndef HAVE_REALLOCARRAY+void *reallocarray(void *ptr, size_t nmemb, size_t size);+#endif+#endif