mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-10-04 07:08:43 +00:00
Add compat for reallocarray()
This function fails safely in the case where the multiplication would overflow.
This commit is contained in:
parent
7ae7543de2
commit
6bb37abd4b
3 changed files with 19 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue