mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-04-22 20:45:01 +00:00
Add compat for reallocarray()
This function fails safely in the case where the multiplication would overflow.
This commit is contained in:
parent
f6ae6865ed
commit
f3998c280b
3 changed files with 19 additions and 1 deletions
|
@ -180,6 +180,7 @@ check_functions = [
|
|||
'vasprintf',
|
||||
'nrand48',
|
||||
'jrand48',
|
||||
'reallocarray',
|
||||
]
|
||||
|
||||
foreach f : check_functions
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -74,4 +74,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
|
||||
|
|
Loading…
Add table
Reference in a new issue