mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Remove dependency of reallocarray()
By removing this dependency, all of the code of this repository is licensed under the MIT license. Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
LICENSE
|
||||
=======
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
|
||||
|
||||
@@ -20,9 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
IN THE SOFTWARE.
|
||||
|
||||
Other
|
||||
-----
|
||||
|
||||
extern/reallocarray.c is derived from the OpenBSD Project,
|
||||
http://www.openbsd.org, and is released under the ISC license.
|
||||
|
||||
2
Makefile
2
Makefile
@@ -57,11 +57,9 @@ rgbasm_obj := \
|
||||
src/asm/rpn.o \
|
||||
src/asm/symbol.o \
|
||||
src/extern/err.o \
|
||||
src/extern/reallocarray.o \
|
||||
src/extern/utf8decoder.o \
|
||||
src/extern/version.o
|
||||
|
||||
|
||||
src/asm/asmy.h: src/asm/asmy.c
|
||||
src/asm/locallex.o src/asm/globlex.o src/asm/lexer.o: src/asm/asmy.h
|
||||
|
||||
|
||||
23
include/extern/reallocarray.h
vendored
23
include/extern/reallocarray.h
vendored
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* This file is part of RGBDS.
|
||||
*
|
||||
* Copyright (c) 2015-2018, RGBDS contributors.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#ifndef EXTERN_REALLOCARRAY_H
|
||||
#define EXTERN_REALLOCARRAY_H
|
||||
|
||||
#ifdef REALLOCARRAY_IN_LIBC
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#else /* REALLOCARRAY_IN_LIBC */
|
||||
|
||||
#define reallocarray rgbds_reallocarray
|
||||
void *reallocarray(void *, size_t, size_t);
|
||||
|
||||
#endif /* REALLOCARRAY_IN_LIBC */
|
||||
|
||||
#endif /* EXTERN_REALLOCARRAY_H */
|
||||
@@ -22,13 +22,14 @@
|
||||
#include "asm/main.h"
|
||||
|
||||
#include "extern/err.h"
|
||||
#include "extern/reallocarray.h"
|
||||
#include "extern/version.h"
|
||||
|
||||
extern int yyparse(void);
|
||||
|
||||
int32_t cldefines_index;
|
||||
int32_t cldefines_size;
|
||||
size_t cldefines_index;
|
||||
size_t cldefines_numindices;
|
||||
size_t cldefines_bufsize;
|
||||
const size_t cldefine_entrysize = 2 * sizeof(void *);
|
||||
char **cldefines;
|
||||
|
||||
clock_t nStartClock, nEndClock;
|
||||
@@ -192,10 +193,18 @@ void opt_AddDefine(char *s)
|
||||
{
|
||||
char *value, *equals;
|
||||
|
||||
if (cldefines_index >= cldefines_size) {
|
||||
cldefines_size *= 2;
|
||||
cldefines = reallocarray(cldefines, cldefines_size,
|
||||
2 * sizeof(void *));
|
||||
if (cldefines_index >= cldefines_numindices) {
|
||||
/* Check for overflows */
|
||||
if ((cldefines_numindices * 2) < cldefines_numindices)
|
||||
fatalerror("No memory for command line defines");
|
||||
|
||||
if ((cldefines_bufsize * 2) < cldefines_bufsize)
|
||||
fatalerror("No memory for command line defines");
|
||||
|
||||
cldefines_numindices *= 2;
|
||||
cldefines_bufsize *= 2;
|
||||
|
||||
cldefines = realloc(cldefines, cldefines_bufsize);
|
||||
if (!cldefines)
|
||||
fatalerror("No memory for command line defines");
|
||||
}
|
||||
@@ -288,8 +297,10 @@ int main(int argc, char *argv[])
|
||||
|
||||
dependfile = NULL;
|
||||
|
||||
cldefines_size = 32;
|
||||
cldefines = reallocarray(cldefines, cldefines_size, 2 * sizeof(void *));
|
||||
/* Initial number of allocated elements in array */
|
||||
cldefines_numindices = 32;
|
||||
cldefines_bufsize = cldefines_numindices * cldefine_entrysize;
|
||||
cldefines = malloc(cldefines_bufsize);
|
||||
if (!cldefines)
|
||||
fatalerror("No memory for command line defines");
|
||||
|
||||
|
||||
37
src/extern/reallocarray.c
vendored
37
src/extern/reallocarray.c
vendored
@@ -1,37 +0,0 @@
|
||||
/* $OpenBSD: reallocarray.c,v 1.2 2014/12/08 03:45:00 bcook Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2008 Otto Moerbeek <otto@drijf.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/*
|
||||
* This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
|
||||
* if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
|
||||
*/
|
||||
#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
|
||||
|
||||
void *rgbds_reallocarray(void *optr, size_t nmemb, size_t size)
|
||||
{
|
||||
if (((nmemb >= MUL_NO_OVERFLOW) || (size >= MUL_NO_OVERFLOW)) &&
|
||||
(nmemb > 0) && (SIZE_MAX / nmemb < size)) {
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
return realloc(optr, size * nmemb);
|
||||
}
|
||||
Reference in New Issue
Block a user