Blame
Date:
Fri Jul 1 20:05:34 2022 UTC
Message:
include config.h in all compats
01
2022-07-01
op
/*
02
2022-07-01
op
* Copyright (c) 2008 Otto Moerbeek <otto@drijf.net>
03
2022-07-01
op
*
04
2022-07-01
op
* Permission to use, copy, modify, and distribute this software for any
05
2022-07-01
op
* purpose with or without fee is hereby granted, provided that the above
06
2022-07-01
op
* copyright notice and this permission notice appear in all copies.
07
2022-07-01
op
*
08
2022-07-01
op
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
09
2022-07-01
op
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
2022-07-01
op
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
2022-07-01
op
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
2022-07-01
op
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
2022-07-01
op
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
2022-07-01
op
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
2022-07-01
op
*/
16
2022-07-01
op
17
2022-07-01
op
#include "config.h"
18
2022-07-01
op
19
2022-07-01
op
#include <sys/types.h>
20
2022-07-01
op
#include <errno.h>
21
2022-07-01
op
#include <stdint.h>
22
2022-07-01
op
#include <stdlib.h>
23
2022-07-01
op
24
2022-07-01
op
/*
25
2022-07-01
op
* This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
26
2022-07-01
op
* if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
27
2022-07-01
op
*/
28
2022-07-01
op
#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
29
2022-07-01
op
30
2022-07-01
op
void *
31
2022-07-01
op
reallocarray(void *optr, size_t nmemb, size_t size)
32
2022-07-01
op
{
33
2022-07-01
op
if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
34
2022-07-01
op
nmemb > 0 && SIZE_MAX / nmemb < size) {
35
2022-07-01
op
errno = ENOMEM;
36
2022-07-01
op
return NULL;
37
2022-07-01
op
}
38
2022-07-01
op
return realloc(optr, size * nmemb);
39
2022-07-01
op
}
Omar Polo