ref: c071586ae53965cbdc8c10643b18e68dc9d2d56b
parent: c6187be210fabe0b377d57c9ce8dd19e18551160
author: Antonio Niño Díaz <[email protected]>
date: Fri Jan 26 19:30:13 EST 2018
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 <[email protected]>
--- a/LICENSE.rst
+++ b/LICENSE.rst
@@ -1,5 +1,4 @@
-LICENSE
-=======
+The MIT License
Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
@@ -20,9 +19,3 @@
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.
--- a/Makefile
+++ b/Makefile
@@ -57,10 +57,8 @@
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
--- a/include/extern/reallocarray.h
+++ /dev/null
@@ -1,23 +1,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 */
--- a/src/asm/main.c
+++ b/src/asm/main.c
@@ -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 @@
{
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 @@
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");
--- a/src/extern/reallocarray.c
+++ /dev/null
@@ -1,37 +1,0 @@
-/* $OpenBSD: reallocarray.c,v 1.2 2014/12/08 03:45:00 bcook Exp $ */
-/*
- * Copyright (c) 2008 Otto Moerbeek <[email protected]>
- *
- * 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);
-}