more fixes for using bool and the stdckdint functions for integer overflow; another update to test from coreutils-9.2 changes; fix memleak in parser state on parse error; Makefile changes for macOS

This commit is contained in:
Chet Ramey
2024-03-28 12:16:15 -04:00
parent 8af5a8e0ca
commit 4f2595eff3
33 changed files with 320 additions and 128 deletions
-4
View File
@@ -67,10 +67,6 @@
extern struct passwd *getpwuid (uid_t);
#endif /* HAVE_GETPWUID && !HAVE_GETPW_DECLS */
#ifndef NULL
# define NULL 0
#endif
#ifndef CHAR_BIT
# define CHAR_BIT 8
#endif
+5 -1
View File
@@ -95,7 +95,7 @@ CSOURCES = clktck.c clock.c getcwd.c getenv.c oslib.c setlinebuf.c \
ufuncs.c casemod.c dprintf.c input_avail.c mbscasecmp.c fnxform.c \
strchrnul.c unicode.c wcswidth.c wcsnwidth.c shmbchar.c strdup.c \
strvis.c strlcpy.c strscpy.c utf8.c random.c gettimeofday.c \
timers.c anonfile.c compat.c
timers.c anonfile.c reallocarray.c compat.c
# The header files for this library.
HSOURCES =
@@ -178,6 +178,7 @@ oslib.o: oslib.c
pathcanon.o: pathcanon.c
pathphys.o: pathphys.c
random.o: random.c
reallocarray.o: reallocarray.c
rename.o: rename.c
setlinebuf.o: setlinebuf.c
shmatch.o: shmatch.c
@@ -265,6 +266,7 @@ oslib.o: ${BUILD_DIR}/config.h
pathcanon.o: ${BUILD_DIR}/config.h
pathphys.o: ${BUILD_DIR}/config.h
random.o: ${BUILD_DIR}/config.h
reallocarray.o: ${BUILD_DIR}/config.h
rename.o: ${BUILD_DIR}/config.h
setlinebuf.o: ${BUILD_DIR}/config.h
shmatch.o: ${BUILD_DIR}/config.h
@@ -691,6 +693,8 @@ anonfile.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h
anonfile.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h
anonfile.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h
reallocarray.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
compat.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
compat.o: ${topdir}/bashtypes.h
compat.o: ${BASHINCDIR}/filecntl.h
+1 -4
View File
@@ -1,6 +1,6 @@
/* fmtulong.c -- Convert unsigned long int to string. */
/* Copyright (C) 1998-2011,2023 Free Software Foundation, Inc.
/* Copyright (C) 1998-2011,2023-2024 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -31,9 +31,6 @@
#endif
#include <bashansi.h>
#ifdef HAVE_STDDEF_H
# include <stddef.h>
#endif
#ifdef HAVE_STDINT_H
# include <stdint.h>
+1 -5
View File
@@ -1,6 +1,6 @@
/* getcwd.c -- get pathname of current directory */
/* Copyright (C) 1991, 2022 Free Software Foundation, Inc.
/* Copyright (C) 1991, 2022, 2024 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -64,10 +64,6 @@ extern int errno;
# define lstat stat
#endif
#if !defined (NULL)
# define NULL 0
#endif
/* If the d_fileno member of a struct dirent doesn't return anything useful,
we need to check inode number equivalence the hard way. Return 1 if
the inode corresponding to PATH/DIR is identical to THISINO. */
+1 -5
View File
@@ -1,6 +1,6 @@
/* makepath.c - glue PATH and DIR together into a full pathname. */
/* Copyright (C) 1987-2020,2022-2023 Free Software Foundation, Inc.
/* Copyright (C) 1987-2020,2022-2024 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -32,10 +32,6 @@
#include <tilde/tilde.h>
#ifndef NULL
# define NULL 0
#endif
/* MAKE SURE THESE AGREE WITH ../../externs.h. */
#ifndef MP_DOTILDE
+44
View File
@@ -0,0 +1,44 @@
/* reallocarray.c - reallocate memory for an array given type size and
number of elements */
/* Copyright (C) 2024 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Bash is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Bash. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include "bashansi.h"
#include <stdckdint.h>
#include <errno.h>
#if !defined (errno)
extern int errno;
#endif
void *
reallocarray (void *ptr, size_t nmemb, size_t size)
{
size_t nbytes;
if (ckd_mul (&nbytes, nmemb, size))
{
errno = ENOMEM;
return NULL;
}
return realloc (ptr, nbytes);
}
+1 -4
View File
@@ -9,7 +9,7 @@
Unix snprintf implementation.
derived from inetutils/libinetutils/snprintf.c Version 1.1
Copyright (C) 2001-2022 Free Software Foundation, Inc.
Copyright (C) 2001-2024 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -94,9 +94,6 @@
# include <limits.h>
#endif
#include <bashansi.h>
#ifdef HAVE_STDDEF_H
# include <stddef.h>
#endif
#include <chartypes.h>
#ifdef HAVE_STDINT_H
+10 -19
View File
@@ -37,34 +37,26 @@
char **
strvec_create (size_t n)
{
size_t nbytes;
return ckd_mul (&nbytes, n, sizeof (char *)) ? NULL : xmalloc (nbytes);
return ((char **)xreallocarray (NULL, n, sizeof (char *)));
}
/* Allocate an array of strings with room for N members. */
char **
strvec_mcreate (size_t n)
{
size_t nbytes;
return ckd_mul (&nbytes, n, sizeof (char *)) ? NULL : malloc (nbytes);
return ((char **)reallocarray (NULL, n, sizeof (char *)));
}
char **
strvec_resize (char **array, size_t nsize)
{
size_t nbytes;
return ckd_mul (&nbytes, nsize, sizeof (char *)) ? NULL : (char **)xrealloc (array, nbytes);
return ((char **)xreallocarray (array, nsize, sizeof (char *)));
}
char **
strvec_mresize (char **array, size_t nsize)
{
size_t nbytes;
return ckd_mul (&nbytes, nsize, sizeof (char *)) ? NULL : (char **)realloc (array, nbytes);
return ((char **)reallocarray (array, nsize, sizeof (char *)));
}
/* Return the length of ARRAY, a NULL terminated array of char *. */
@@ -103,7 +95,7 @@ strvec_dispose (char **array)
int
strvec_remove (char **array, const char *name)
{
register int i, j;
size_t i, j;
char *x;
if (array == 0)
@@ -123,10 +115,10 @@ strvec_remove (char **array, const char *name)
/* Find NAME in ARRAY. Return the index of NAME, or -1 if not present.
ARRAY should be NULL terminated. */
int
ptrdiff_t
strvec_search (char **array, const char *name)
{
int i;
size_t i;
for (i = 0; array[i]; i++)
if (STREQ (name, array[i]))
@@ -139,8 +131,7 @@ strvec_search (char **array, const char *name)
char **
strvec_copy (char * const *array)
{
int i;
size_t len;
size_t i, len;
char **ret;
len = strvec_len (array);
@@ -212,7 +203,7 @@ strvec_sort (char **array, int posix)
char **
strvec_from_word_list (WORD_LIST *list, int alloc, int starting_index, int *ip)
{
int count;
size_t count;
char **array;
count = list_length ((GENERIC_LIST *)list);
@@ -239,7 +230,7 @@ strvec_to_word_list (char **array, int alloc, int starting_index)
{
WORD_LIST *list;
WORD_DESC *w;
int i, count;
size_t i, count;
if (array == 0 || array[0] == 0)
return (WORD_LIST *)NULL;
+1 -5
View File
@@ -1,6 +1,6 @@
/* strtod.c - convert string to double-precision floating-point value. */
/* Copyright (C) 1991, 1992, 2022 Free Software Foundation, Inc.
/* Copyright (C) 1991, 1992, 2022-2024 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -41,10 +41,6 @@ extern int errno;
#include <bashansi.h>
#ifndef NULL
# define NULL 0
#endif
#ifndef HUGE_VAL
# define HUGE_VAL HUGE
#endif
+1 -5
View File
@@ -1,6 +1,6 @@
/* strtol - convert string representation of a number into a long integer value. */
/* Copyright (C) 1991-2001,2022 Free Software Foundation, Inc.
/* Copyright (C) 1991-2024 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -42,10 +42,6 @@ extern int errno;
#include <stdc.h>
#include <bashansi.h>
#ifndef NULL
# define NULL 0
#endif
/* Nonzero if we are defining `strtoul' or `strtoull', operating on
unsigned integers. */
#ifndef UNSIGNED