summaryrefslogtreecommitdiff
path: root/braces.c
diff options
context:
space:
mode:
authorChet Ramey <chet.ramey@case.edu>2019-01-07 09:27:52 -0500
committerChet Ramey <chet.ramey@case.edu>2019-01-07 09:27:52 -0500
commitd233b485e83c3a784b803fb894280773f16f2deb (patch)
tree16d51f3ccca2d4ad2d8f2da564d68ca848de595b /braces.c
parent64447609994bfddeef1061948022c074093e9a9f (diff)
downloadbash-d233b485e83c3a784b803fb894280773f16f2deb.tar.gz
bash-5.0 distribution sources and documentationbash-5.0
Diffstat (limited to 'braces.c')
-rw-r--r--braces.c33
1 files changed, 12 insertions, 21 deletions
diff --git a/braces.c b/braces.c
index 7f31dd5e..485de369 100644
--- a/braces.c
+++ b/braces.c
@@ -1,6 +1,6 @@
/* braces.c -- code for doing word expansion in curly braces. */
-/* Copyright (C) 1987-2012 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2018 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -61,7 +61,9 @@ extern int errno;
extern int asprintf __P((char **, const char *, ...)) __attribute__((__format__ (printf, 2, 3)));
+#if defined (NOTDEF)
extern int last_command_exit_value;
+#endif
/* Basic idea:
@@ -383,7 +385,7 @@ mkseq (start, end, incr, type, width)
int type, width;
{
intmax_t n, prevn;
- int i, j, nelem;
+ int i, nelem;
char **result, *t;
if (incr == 0)
@@ -418,13 +420,13 @@ mkseq (start, end, incr, type, width)
/* Instead of a simple nelem = prevn + 1, something like:
nelem = (prevn / imaxabs(incr)) + 1;
would work */
- nelem = (prevn / sh_imaxabs(incr)) + 1;
- if (nelem > INT_MAX - 2) /* Don't overflow int */
+ if ((prevn / sh_imaxabs (incr)) > INT_MAX - 3) /* check int overflow */
return ((char **)NULL);
+ nelem = (prevn / sh_imaxabs(incr)) + 1;
result = strvec_mcreate (nelem + 1);
if (result == 0)
{
- internal_error (_("brace expansion: failed to allocate memory for %d elements"), nelem);
+ internal_error (_("brace expansion: failed to allocate memory for %u elements"), (unsigned int)nelem);
return ((char **)NULL);
}
@@ -436,6 +438,7 @@ mkseq (start, end, incr, type, width)
#if defined (SHELL)
if (ISINTERRUPT)
{
+ result[i] = (char *)NULL;
strvec_dispose (result);
result = (char **)NULL;
}
@@ -494,7 +497,7 @@ expand_seqterm (text, tlen)
size_t tlen;
{
char *t, *lhs, *rhs;
- int i, lhs_t, rhs_t, lhs_l, rhs_l, width;
+ int lhs_t, rhs_t, lhs_l, rhs_l, width;
intmax_t lhs_v, rhs_v, incr;
intmax_t tl, tr;
char **result, *ep, *oep;
@@ -743,20 +746,6 @@ comsub:
return (c);
}
-/* Return 1 if ARR has any non-empty-string members. Used to short-circuit
- in array_concat() below. */
-static int
-degenerate_array (arr)
- char **arr;
-{
- register int i;
-
- for (i = 0; arr[i]; i++)
- if (arr[i][0] != '\0')
- return 0;
- return 1;
-}
-
/* Return a new array of strings which is the result of appending each
string in ARR2 to each string in ARR1. The resultant array is
len (arr1) * len (arr2) long. For convenience, ARR1 (and its contents)
@@ -790,7 +779,9 @@ array_concat (arr1, arr2)
len1 = strvec_len (arr1);
len2 = strvec_len (arr2);
- result = (char **)xmalloc ((1 + (len1 * len2)) * sizeof (char *));
+ result = (char **)malloc ((1 + (len1 * len2)) * sizeof (char *));
+ if (result == 0)
+ return (result);
len = 0;
for (i = 0; i < len1; i++)