diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 48e4663a..227bb13b 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -12630,3 +12630,34 @@ parse.y subst.c - parameter_brace_expand_indir: clean up checks for unset variables to minimize incompatibilities with previous versions + + 12/5 + ---- +lib/readline/history.c + - add_history: don't update history_length until all of the updates to + the_history are complete, so history_length is always consistent. + Report and fix from Hong Cho + +bashline.c + - bash_backward_shellword: fix to work better at the end of the line, + with multiple trailing whitespace characters. Inspired by report + from Kirill Timofeev + +Makefile.in + - bashbug: use `^' as the sed delimiter instead of `%'; some compilers + use `%' in CFLAGS. Report from Vladimir Marek + + + 12/6 + ---- +test.c + - test_unop: make sure op[1] != 0 before testing op[2] + - term: make sure argv[pos][1] != 0 before testing argv[pos][2]. Fixes + oob-read reported by Jerzy Kramarz + + 12/7 + ---- +lib/glob/glob.c + - glob_filename: assign the return value of realloc (results, ...) to + a temp pointer, so if realloc returns NULL, we make sure we free + results. Report from Kirill Timofeev diff --git a/Makefile.in b/Makefile.in index 424aee86..82684a9d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -584,12 +584,9 @@ $(Program): .build $(OBJECTS) $(BUILTINS_DEP) $(LIBDEP) @echo " ***********************************************************" @echo -bashbug: $(SUPPORT_SRC)bashbug.sh config.h Makefile $(VERSPROG) - @sed -e "s%!MACHINE!%$(Machine)%" -e "s%!OS!%$(OS)%" \ - -e "s%!CFLAGS!%$(CCFLAGS)%" -e "s%!CC!%$(CC)%" \ - -e "s%!RELEASE!%$(Version)%" -e "s%!PATCHLEVEL!%$(PatchLevel)%" \ - -e "s%!MACHTYPE!%$(MACHTYPE)%" -e "s%!RELSTATUS!%$(RELSTATUS)%" \ - $(SUPPORT_SRC)bashbug.sh > $@ +bashbug: $(SDIR)/bashbug.sh config.h Makefile $(VERSPROG) + @sed -e "s%!PATCHLEVEL!%$(PatchLevel)%" \ + $(SDIR)/bashbug.sh > $@ @chmod a+rx bashbug strip: $(Program) .made diff --git a/bashline.c b/bashline.c index 735e23b9..f6cd75b7 100644 --- a/bashline.c +++ b/bashline.c @@ -1173,7 +1173,10 @@ bash_backward_shellword (count, key) p = rl_point; slen = rl_end; - + + if (p == rl_end && p > 0) + p--; + while (count) { if (p == 0) @@ -1186,9 +1189,9 @@ bash_backward_shellword (count, key) while (p > 0) { c = rl_line_buffer[p]; - if (WORDDELIM (c) && char_is_quoted (rl_line_buffer, p) == 0) - BACKUP_CHAR (rl_line_buffer, slen, p); - break; + if (WORDDELIM (c) == 0 || char_is_quoted (rl_line_buffer, p)) + break; + BACKUP_CHAR (rl_line_buffer, slen, p); } if (p == 0) @@ -1639,7 +1642,7 @@ bash_default_completion (text, start, end, qc, compflags) matches = (char **)NULL; /* New posix-style command substitution or variable name? */ - if (!matches && *text == '$') + if (*text == '$') { if (qc != '\'' && text[1] == '(') /* ) */ matches = rl_completion_matches (text, command_subst_completion_function); diff --git a/command.h b/command.h index 3da5b77d..3bf479ac 100644 --- a/command.h +++ b/command.h @@ -101,6 +101,7 @@ enum command_type { cm_for, cm_case, cm_while, cm_if, cm_simple, cm_select, #define W_ASSNGLOBAL 0x2000000 /* word is a global assignment to declare (declare/typeset -g) */ #define W_NOBRACE 0x4000000 /* Don't perform brace expansion */ #define W_COMPLETE 0x8000000 /* word is being expanded for completion */ +#define W_CHKLOCAL 0x10000000 /* check for local vars on assignment */ /* Flags for the `pflags' argument to param_expand() and various parameter_brace_expand_xxx functions; also used for string_list_dollar_at */ diff --git a/configure b/configure index 2cea9feb..40438402 100755 --- a/configure +++ b/configure @@ -16288,7 +16288,7 @@ fi #AC_SUBST(ALLOCA_SOURCE) #AC_SUBST(ALLOCA_OBJECT) -ac_config_files="$ac_config_files Makefile builtins/Makefile lib/readline/Makefile lib/glob/Makefile lib/intl/Makefile lib/malloc/Makefile lib/sh/Makefile lib/termcap/Makefile lib/tilde/Makefile doc/Makefile support/Makefile po/Makefile.in examples/loadables/Makefile examples/loadables/Makefile.inc examples/loadables/perl/Makefile support/bash.pc" +ac_config_files="$ac_config_files Makefile builtins/Makefile lib/readline/Makefile lib/glob/Makefile lib/intl/Makefile lib/malloc/Makefile lib/sh/Makefile lib/termcap/Makefile lib/tilde/Makefile doc/Makefile support/Makefile po/Makefile.in examples/loadables/Makefile examples/loadables/Makefile.inc examples/loadables/perl/Makefile support/bash.pc support/bashbug.sh" ac_config_commands="$ac_config_commands default" @@ -17016,6 +17016,7 @@ do "examples/loadables/Makefile.inc") CONFIG_FILES="$CONFIG_FILES examples/loadables/Makefile.inc" ;; "examples/loadables/perl/Makefile") CONFIG_FILES="$CONFIG_FILES examples/loadables/perl/Makefile" ;; "support/bash.pc") CONFIG_FILES="$CONFIG_FILES support/bash.pc" ;; + "support/bashbug.sh") CONFIG_FILES="$CONFIG_FILES support/bashbug.sh" ;; "default") CONFIG_COMMANDS="$CONFIG_COMMANDS default" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; diff --git a/configure.ac b/configure.ac index 552773bf..4a28b56f 100644 --- a/configure.ac +++ b/configure.ac @@ -1237,7 +1237,7 @@ AC_OUTPUT([Makefile builtins/Makefile lib/readline/Makefile lib/glob/Makefile \ lib/tilde/Makefile doc/Makefile support/Makefile po/Makefile.in \ examples/loadables/Makefile examples/loadables/Makefile.inc \ examples/loadables/perl/Makefile \ - support/bash.pc], + support/bash.pc support/bashbug.sh], [ # Makefile uses this timestamp file to record whether config.h is up to date. echo timestamp > stamp-h diff --git a/doc/bash.1 b/doc/bash.1 index 5c27d564..7c3496d7 100644 --- a/doc/bash.1 +++ b/doc/bash.1 @@ -3710,6 +3710,12 @@ Matches one of the given patterns Matches anything except one of the given patterns .RE .PD +.PP +Complicated extended pattern matching against long strings is slow, +especially when the patterns contain alternations and the strings +contain multiple matches. +Using separate matches against shorter strings, or using arrays of +strings instead of a single long string, may be faster. .SS Quote Removal .PP After the preceding expansions, all unquoted occurrences of the diff --git a/doc/bashref.texi b/doc/bashref.texi index b2dff8c0..aefe3e4a 100644 --- a/doc/bashref.texi +++ b/doc/bashref.texi @@ -2536,6 +2536,12 @@ Matches one of the given patterns. Matches anything except one of the given patterns. @end table +Complicated extended pattern matching against long strings is slow, +especially when the patterns contain alternations and the strings +contain multiple matches. +Using separate matches against shorter strings, or using arrays of +strings instead of a single long string, may be faster. + @node Quote Removal @subsection Quote Removal diff --git a/execute_cmd.c b/execute_cmd.c index f6ce256e..27ef9668 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -2225,7 +2225,7 @@ coproc_setvars (cp) t = itos (cp->c_wfd); ind = 1; - bind_array_variable (cp->c_name, ind, t, 0); + v = bind_array_variable (cp->c_name, ind, t, 0); free (t); #else sprintf (namevar, "%s_READ", cp->c_name); @@ -2240,7 +2240,7 @@ coproc_setvars (cp) sprintf (namevar, "%s_PID", cp->c_name); t = itos (cp->c_pid); - bind_variable (namevar, t, 0); + v = bind_variable (namevar, t, 0); free (t); free (namevar); @@ -3798,7 +3798,6 @@ execute_cond_command (cond_command) { int retval, save_line_number; - retval = EXECUTION_SUCCESS; save_line_number = line_number; this_command_name = "[["; @@ -3981,9 +3980,10 @@ fix_assignment_words (words) /* If we have an assignment builtin that does not create local variables, make sure we create global variables even if we internally call - `declare' */ + `declare'. The CHKLOCAL flag means to set attributes or values on + an existing local variable */ if (b && ((b->flags & (ASSIGNMENT_BUILTIN|LOCALVAR_BUILTIN)) == ASSIGNMENT_BUILTIN)) - w->word->flags |= W_ASSNGLOBAL; + w->word->flags |= W_ASSNGLOBAL|W_CHKLOCAL; } #if defined (ARRAY_VARS) /* Note that we saw an associative array option to a builtin that takes @@ -4086,7 +4086,7 @@ execute_simple_command (simple_command, pipe_in, pipe_out, async, fds_to_close) last_command_subst_pid = NO_PID; old_last_async_pid = last_asynchronous_pid; - already_forked = dofork = 0; + already_forked = 0; /* If we're in a pipeline or run in the background, set DOFORK so we make the child early, before word expansion. This keeps assignment diff --git a/lib/glob/glob.c b/lib/glob/glob.c index 7f6eafe7..796ee9d6 100644 --- a/lib/glob/glob.c +++ b/lib/glob/glob.c @@ -1018,7 +1018,7 @@ glob_filename (pathname, flags) char *pathname; int flags; { - char **result; + char **result, **new_result; unsigned int result_size; char *directory_name, *filename, *dname, *fn; unsigned int directory_len; @@ -1248,16 +1248,16 @@ glob_filename (pathname, flags) while (array[l] != NULL) ++l; - result = - (char **)realloc (result, (result_size + l) * sizeof (char *)); + new_result = (char **)realloc (result, (result_size + l) * sizeof (char *)); - if (result == NULL) + if (new_result == NULL) { for (l = 0; array[l]; ++l) free (array[l]); free ((char *)array); goto memory_error; } + result = new_result; for (l = 0; array[l] != NULL; ++l) result[result_size++ - 1] = array[l]; diff --git a/lib/readline/history.c b/lib/readline/history.c index a21d0d88..4362837e 100644 --- a/lib/readline/history.c +++ b/lib/readline/history.c @@ -279,6 +279,7 @@ add_history (string) const char *string; { HIST_ENTRY *temp; + int new_length; if (history_stifled && (history_length == history_max_entries)) { @@ -295,13 +296,9 @@ add_history (string) /* Copy the rest of the entries, moving down one slot. Copy includes trailing NULL. */ -#if 0 - for (i = 0; i < history_length; i++) - the_history[i] = the_history[i + 1]; -#else memmove (the_history, the_history + 1, history_length * sizeof (HIST_ENTRY *)); -#endif + new_length = history_length; history_base++; } else @@ -315,7 +312,7 @@ add_history (string) else history_size = DEFAULT_HISTORY_INITIAL_SIZE; the_history = (HIST_ENTRY **)xmalloc (history_size * sizeof (HIST_ENTRY *)); - history_length = 1; + new_length = 1; } else { @@ -325,14 +322,15 @@ add_history (string) the_history = (HIST_ENTRY **) xrealloc (the_history, history_size * sizeof (HIST_ENTRY *)); } - history_length++; + new_length = history_length + 1; } } temp = alloc_history_entry ((char *)string, hist_inittime ()); - the_history[history_length] = (HIST_ENTRY *)NULL; - the_history[history_length - 1] = temp; + the_history[new_length] = (HIST_ENTRY *)NULL; + the_history[new_length - 1] = temp; + history_length = new_length; } /* Change the time stamp of the most recent history entry to STRING. */ diff --git a/subst.c b/subst.c index e29cce8a..55dae72c 100644 --- a/subst.c +++ b/subst.c @@ -518,6 +518,11 @@ dump_word_flags (flags) f &= ~W_COMPLETE; fprintf (stderr, "W_COMPLETE%s", f ? "|" : ""); } + if (f & W_CHKLOCAL) + { + f &= ~W_CHKLOCAL; + fprintf (stderr, "W_CHKLOCAL%s", f ? "|" : ""); + } fprintf (stderr, "\n"); fflush (stderr); @@ -3054,7 +3059,7 @@ do_compound_assignment (name, value, flags) v = find_variable (name); if (v && ((readonly_p (v) && (flags & ASS_FORCE) == 0) || noassign_p (v))) { - if (v && readonly_p (v)) + if (readonly_p (v)) err_readonly (name); return (v); /* XXX */ } @@ -3074,7 +3079,7 @@ do_compound_assignment (name, value, flags) v = find_global_variable (name); if (v && ((readonly_p (v) && (flags & ASS_FORCE) == 0) || noassign_p (v))) { - if (v && readonly_p (v)) + if (readonly_p (v)) err_readonly (name); return (v); /* XXX */ } @@ -3097,7 +3102,7 @@ do_compound_assignment (name, value, flags) v = assign_array_from_string (name, value, flags); if (v && ((readonly_p (v) && (flags & ASS_FORCE) == 0) || noassign_p (v))) { - if (v && readonly_p (v)) + if (readonly_p (v)) err_readonly (name); return (v); /* XXX */ } diff --git a/test.c b/test.c index d27a463c..6b54e32f 100644 --- a/test.c +++ b/test.c @@ -274,7 +274,7 @@ term () value = binary_operator (); /* Might be a switch type argument */ - else if (argv[pos][0] == '-' && argv[pos][2] == '\0') + else if (argv[pos][0] == '-' && argv[pos][1] && argv[pos][2] == '\0') { if (test_unop (argv[pos])) value = unary_operator (); @@ -718,7 +718,7 @@ int test_unop (op) char *op; { - if (op[0] != '-' || op[2] != 0) + if (op[0] != '-' || (op[1] && op[2] != 0)) return (0); switch (op[1]) diff --git a/tests/comsub2.sub b/tests/comsub2.sub index c59bec82..d60ae6a0 100644 --- a/tests/comsub2.sub +++ b/tests/comsub2.sub @@ -4,5 +4,5 @@ echo "$qpath" # it's crazy that all three of these produce the same result printf "%s\n" ${qpath//\\/} -printf "%s\n" ${qpath//"`echo \\`"/} -printf "%s\n" ${qpath//`echo "\\\\\\\\"`/} +printf "%s\n" ${qpath//"`printf '%s' \\`"/} +printf "%s\n" ${qpath//`printf '%s' "\\\\\\\\"`/} diff --git a/tests/execscript b/tests/execscript index 0866c561..c1819de7 100644 --- a/tests/execscript +++ b/tests/execscript @@ -59,10 +59,10 @@ echo $? echo $? # kill two birds with one test -- test out the BASH_ENV code -echo echo this is bashenv > /tmp/bashenv -export BASH_ENV=/tmp/bashenv +echo echo this is bashenv > $TMPDIR/bashenv +export BASH_ENV=$TMPDIR/bashenv ${THIS_SH} ./exec3.sub -rm -f /tmp/bashenv +rm -f $TMPDIR/bashenv unset BASH_ENV # we're resetting the $PATH to empty, so this should be last diff --git a/tests/exp.right b/tests/exp.right index 35310377..96617397 100644 --- a/tests/exp.right +++ b/tests/exp.right @@ -226,7 +226,7 @@ declare -- var="x\001y\177z"$ argv[1] = <$'x\001y\177z'> argv[1] = var=$'x\001y\177z' -./exp8.sub: line 18: xyz: syntax error: invalid arithmetic operator (error token is "z") +./exp8.sub: line 16: xyz: syntax error: invalid arithmetic operator (error token is "z") declare -a array=() declare -a array=([0]=$'x\001y\177z') argv[1] = diff --git a/tests/exp5.sub b/tests/exp5.sub index 63197718..52dd4a15 100644 --- a/tests/exp5.sub +++ b/tests/exp5.sub @@ -1,16 +1,14 @@ # expansions involving patterns -shopt -u xpg_echo - var='[hello' echo "${var//[/}" red='\[\e[0;31m\]' -echo "${red//\\[\\e/}" +printf "%s\n" "${red//\\[\\e/}" foo="${red//\\[\\e/}" # foo == [0;31m\] -echo "${foo//[0;31m\\/}" +printf "%s\n" "${foo//[0;31m\\/}" echo "${var//[]/}" echo "${red//[]/}" diff --git a/tests/exp8.sub b/tests/exp8.sub index 4dede35d..ff44febc 100644 --- a/tests/exp8.sub +++ b/tests/exp8.sub @@ -1,5 +1,3 @@ -shopt -u xpg_echo - var=$'x\001y\177z' recho "$var" @@ -12,11 +10,11 @@ declare -p var | sed -n l recho ${var@Q} recho ${var@P} -echo ${var@A} +echo -E ${var@A} unset array array=( [$'x\001y\177z']=foo ) # should be error -echo ${array[@]@A} +echo -E ${array[@]@A} unset array declare -a array=([0]=$'x\001y\177z') @@ -25,9 +23,9 @@ declare -p array unset array array=( "$var" ) recho ${array[@]} -echo ${array[@]@A} +echo -E ${array[@]@A} unset array declare -A array array=( [$'x\001y\177z']=$'a\242b\002c' ) -echo ${array[@]@A} +echo -E ${array[@]@A} diff --git a/tests/extglob3.sub b/tests/extglob3.sub index 94567ee9..8511b67f 100644 --- a/tests/extglob3.sub +++ b/tests/extglob3.sub @@ -1,5 +1,5 @@ shopt -s extglob -DIR=/tmp/extglob-$$ +DIR=$TMPDIR/extglob-$$ mkdir $DIR cd $DIR @@ -18,4 +18,3 @@ echo !(foo)* cd $OLDPWD rm -rf $DIR - diff --git a/tests/glob.tests b/tests/glob.tests index 20960fb4..5e9a1e13 100644 --- a/tests/glob.tests +++ b/tests/glob.tests @@ -13,7 +13,7 @@ ${THIS_SH} ./glob2.sub MYDIR=$PWD # save where we are -TESTDIR=/tmp/glob-test +TESTDIR=$TMPDIR/glob-test-$$ mkdir $TESTDIR builtin cd $TESTDIR || { echo $0: cannot cd to $TESTDIR >&2 ; exit 1; } rm -rf * diff --git a/tests/heredoc.right b/tests/heredoc.right index 485bdf71..5e596a60 100644 --- a/tests/heredoc.right +++ b/tests/heredoc.right @@ -20,7 +20,7 @@ jkl mno fff is a function fff () { - ed /tmp/foo < /dev/null + ed ${TMPDIR}/foo < /dev/null /^name/d w q @@ -31,7 +31,7 @@ ENDOFINPUT fff is a function fff () { - ed /tmp/foo < /dev/null + ed ${TMPDIR}/foo < /dev/null /^name/d w q diff --git a/tests/heredoc.tests b/tests/heredoc.tests index ebc770ac..ba74e3b6 100644 --- a/tests/heredoc.tests +++ b/tests/heredoc.tests @@ -59,22 +59,22 @@ cat <<- EOF EOF # check appending of text to file from here document -rm -f /tmp/bash-zzz -cat > /tmp/bash-zzz << EOF +rm -f ${TMPDIR}/bash-zzz +cat > ${TMPDIR}/bash-zzz << EOF abc EOF -cat >> /tmp/bash-zzz << EOF +cat >> ${TMPDIR}/bash-zzz << EOF def ghi jkl mno EOF -cat /tmp/bash-zzz -rm -f /tmp/bash-zzz +cat ${TMPDIR}/bash-zzz +rm -f ${TMPDIR}/bash-zzz # make sure command printing puts the here-document as the last redirection # on the line, and the function export code preserves syntactic correctness fff() { - ed /tmp/foo </dev/null + ed ${TMPDIR}/foo </dev/null /^name/d w q diff --git a/tests/histexp.right b/tests/histexp.right index ed6e0894..86ba1371 100644 --- a/tests/histexp.right +++ b/tests/histexp.right @@ -8,7 +8,7 @@ echo $BASH_VERSION 2 /bin/sh -c 'echo this is $0' 3 ls 4 echo $BASH_VERSION - 5 HISTFILE=/tmp/newhistory + 5 HISTFILE=$TMPDIR/newhistory 6 echo line 2 for history echo line 2 for history echo line 2 for history @@ -19,7 +19,7 @@ line 2 for history 2 /bin/sh -c 'echo this is $0' 3 ls 4 echo $BASH_VERSION - 5 HISTFILE=/tmp/newhistory + 5 HISTFILE=$TMPDIR/newhistory 6 echo line 2 for history 7 set -H 8 echo line 2 for history diff --git a/tests/histexp.tests b/tests/histexp.tests index 99c7520d..2901064f 100644 --- a/tests/histexp.tests +++ b/tests/histexp.tests @@ -1,6 +1,6 @@ LC_ALL=C LANG=C -trap 'rm /tmp/newhistory' 0 +trap 'rm $TMPDIR/newhistory' 0 file=bax histchars='!^#' # make sure history comment char is set correctly @@ -25,7 +25,7 @@ history -p '!!:z' history -HISTFILE=/tmp/newhistory +HISTFILE=$TMPDIR/newhistory history -a history -w diff --git a/tests/history.right b/tests/history.right index de8e22b4..e429d520 100644 --- a/tests/history.right +++ b/tests/history.right @@ -36,13 +36,13 @@ echo line for history echo line for history displaying $HISTFILE after history -a echo line for history -HISTFILE=/tmp/newhistory +HISTFILE=$TMPDIR/newhistory 1 for i in one two three; do echo $i; done 2 /bin/sh -c 'echo this is $0' 3 ls 4 echo $BASH_VERSION 5 echo line for history - 6 HISTFILE=/tmp/newhistory + 6 HISTFILE=$TMPDIR/newhistory 7 echo displaying \$HISTFILE after history -a 8 cat $HISTFILE for i in one two three; do echo $i; done @@ -50,7 +50,7 @@ for i in one two three; do echo $i; done ls echo $BASH_VERSION echo line for history -HISTFILE=/tmp/newhistory +HISTFILE=$TMPDIR/newhistory echo displaying \$HISTFILE after history -a cat $HISTFILE 1 for i in one two three; do echo $i; done @@ -58,7 +58,7 @@ cat $HISTFILE 3 ls 4 echo $BASH_VERSION 5 echo line for history - 6 HISTFILE=/tmp/newhistory + 6 HISTFILE=$TMPDIR/newhistory 7 echo displaying \$HISTFILE after history -a 8 cat $HISTFILE 9 echo line 2 for history @@ -69,7 +69,7 @@ echo line 2 for history 3 ls 4 echo $BASH_VERSION 5 echo line for history - 6 HISTFILE=/tmp/newhistory + 6 HISTFILE=$TMPDIR/newhistory 7 echo displaying \$HISTFILE after history -a 8 cat $HISTFILE 9 echo line 2 for history @@ -80,7 +80,7 @@ echo line 2 for history line 2 for history 4 echo $BASH_VERSION 5 echo line for history -6 HISTFILE=/tmp/newhistory +6 HISTFILE=$TMPDIR/newhistory 7 echo displaying \$HISTFILE after history -a 8 cat $HISTFILE 9 echo line 2 for history @@ -94,7 +94,7 @@ line 2 for history 17 unset HISTFILE 4 echo $BASH_VERSION 5 echo line for history -6 HISTFILE=/tmp/newhistory +6 HISTFILE=$TMPDIR/newhistory 7 echo displaying \$HISTFILE after history -a 8 cat $HISTFILE ./history.tests: line 75: fc: history specification out of range diff --git a/tests/history.tests b/tests/history.tests index f976fbdf..ab1c38c3 100644 --- a/tests/history.tests +++ b/tests/history.tests @@ -1,4 +1,4 @@ -trap 'rm /tmp/newhistory' 0 +trap 'rm $TMPDIR/newhistory' 0 # bad options history -x @@ -39,7 +39,7 @@ history -p '!!' fc -nl -HISTFILE=/tmp/newhistory +HISTFILE=$TMPDIR/newhistory history -a echo displaying \$HISTFILE after history -a cat $HISTFILE diff --git a/tests/jobs1.sub b/tests/jobs1.sub index aa9a3726..53f66cc6 100644 --- a/tests/jobs1.sub +++ b/tests/jobs1.sub @@ -2,7 +2,7 @@ set -m sleep 60 & -FN=/tmp/jobs-pid.$$ +FN=$TMPDIR/jobs-pid.$$ pid1=$! jobs -p %+ > $FN diff --git a/tests/new-exp.right b/tests/new-exp.right index 9913fbd6..e95fa539 100644 --- a/tests/new-exp.right +++ b/tests/new-exp.right @@ -169,11 +169,10 @@ lines. This-string-has-multiple-lines. this is a test of proc subst this is test 2 -./new-exp2.sub: line 31: /tmp/bashtmp.x*: No such file or directory -./new-exp2.sub: line 35: /tmp/redir-notthere: No such file or directory +./new-exp2.sub: line 42: /tmp/redir-notthere: No such file or directory 1 -./new-exp2.sub: line 42: 1111111111111111111111: command not found +./new-exp2.sub: line 49: 1111111111111111111111: command not found argv[1] = <6> ./new-exp.tests: line 285: ${#:}: bad substitution diff --git a/tests/new-exp1.sub b/tests/new-exp1.sub index c015c223..a919ba72 100644 --- a/tests/new-exp1.sub +++ b/tests/new-exp1.sub @@ -1,3 +1,4 @@ +FN=${TMPDIR}/bashtest-$$ expect() { echo expect "$@" @@ -5,7 +6,7 @@ expect() expect this is a test of proc subst cat <(echo this is a test of proc subst) -echo this is test 2 > /tmp/x +echo this is test 2 > $FN expect this is test 2 -cat <(cat /tmp/x) -rm -f /tmp/x +cat <(cat $FN) +rm -f $FN diff --git a/tests/new-exp2.sub b/tests/new-exp2.sub index e8377799..ea52b3ce 100644 --- a/tests/new-exp2.sub +++ b/tests/new-exp2.sub @@ -4,7 +4,7 @@ export LANG=C # test out the new $(< filename) code # it should be exactly equivalent to $(cat filename) -FILENAME=/tmp/bashtmp.x$$ +FILENAME=$TMPDIR/bashtmp.x$$ trap 'rm -f $FILENAME' 0 @@ -21,17 +21,24 @@ if [[ $LINES1 != $LINES2 ]]; then echo 'whoops: $(< filename) failed' fi -LINES2=$(< /tmp/bashtmp.x*) +LINES2=$(< $TMPDIR/bashtmp.x*) if [[ $LINES1 != $LINES2 ]]; then echo 'whoops: $(< filename) with glob expansion failed' fi # but the glob expansion in the redirection should fail in posix mode set -o posix -LINES2=$(< /tmp/bashtmp.x*) +exec 3>&2 +exec 2>/dev/null +LINES2=$(< $TMPDIR/bashtmp.x*) +exec 2>&3 +if [[ $LINES2 -gt 0 ]]; then + echo "whoops: redirection glob expansion should be disabled in posix mode" >&2 +fi set +o posix # now see what happens when we try it with a non-existant file +rm -f /tmp/redir-notthere LINES3=$(< /tmp/redir-notthere) echo $? diff --git a/tests/read.tests b/tests/read.tests index fe27dae3..f67cd00e 100644 --- a/tests/read.tests +++ b/tests/read.tests @@ -25,43 +25,43 @@ echo $'\177' | ( read ; recho "$REPLY" ) # the input stream echo $'ab\\\ncd' | ( read ; recho "$REPLY" ) -echo "A B " > /tmp/IN +echo "A B " > $TMPDIR/IN unset x y z -read x y z < /tmp/IN +read x y z < $TMPDIR/IN echo 1: "x[$x] y[$y] z[$z]" echo 1a: ${z-z not set} -read x < /tmp/IN +read x < $TMPDIR/IN echo 2: "x[$x]" -rm /tmp/IN +rm $TMPDIR/IN # this is where the bash `read' behavior with respect to $REPLY differs # from ksh93 -echo "A B " > /tmp/IN +echo "A B " > $TMPDIR/IN -read < /tmp/IN +read < $TMPDIR/IN echo "[$REPLY]" -rm /tmp/IN +rm $TMPDIR/IN -echo " A B " > /tmp/IN +echo " A B " > $TMPDIR/IN -read < /tmp/IN +read < $TMPDIR/IN echo "[$REPLY]" -rm /tmp/IN +rm $TMPDIR/IN # make sure that read with more variables than words sets the extra # variables to the empty string bvar=bvar cvar=cvar -echo aa > /tmp/IN -read avar bvar cvar < /tmp/IN +echo aa > $TMPDIR/IN +read avar bvar cvar < $TMPDIR/IN echo =="$avar"== echo =="$bvar"== echo =="$cvar"== -rm /tmp/IN +rm $TMPDIR/IN # test behavior of read with various settings of IFS diff --git a/tests/redir.right b/tests/redir.right index c158e251..a9ad7532 100644 --- a/tests/redir.right +++ b/tests/redir.right @@ -26,10 +26,10 @@ from stdin: aa to stdout ./redir4.sub: line 32: $fd: ambiguous redirect ./redir4.sub: line 33: $fd: ambiguous redirect -/tmp/err-and-out: +err-and-out: to stdout to stderr -/tmp/err-and-out: +err-and-out: to stdout to stderr 0 -- 3 0 diff --git a/tests/redir4.sub b/tests/redir4.sub index 47344554..14406d01 100644 --- a/tests/redir4.sub +++ b/tests/redir4.sub @@ -34,23 +34,23 @@ exec 4>&$fd exec 3>&1 4>&2 -exec >&/tmp/err-and-out +exec >&${TMPDIR}/err-and-out echo to stdout echo to stderr >&2 exec 1>&3 2>&4 -echo /tmp/err-and-out: -cat /tmp/err-and-out +echo err-and-out: +cat ${TMPDIR}/err-and-out -rm /tmp/err-and-out +rm ${TMPDIR}/err-and-out -fd=/tmp/err-and-out +fd=${TMPDIR}/err-and-out exec >&$fd echo to stdout echo to stderr >&2 exec 1>&3 2>&4 -echo /tmp/err-and-out: -cat /tmp/err-and-out +echo err-and-out: +cat ${TMPDIR}/err-and-out -rm /tmp/err-and-out +rm ${TMPDIR}/err-and-out diff --git a/variables.c b/variables.c index f157561a..ead80dd5 100644 --- a/variables.c +++ b/variables.c @@ -4729,7 +4729,7 @@ push_func_var (data) /* XXX - should we set v->context here? */ v = bind_variable_internal (var->name, value_cell (var), shell_variables->table, 0, 0); #if defined (ARRAY_VARS) - if (array_p (var) || assoc_p (var)) + if (v && (array_p (var) || assoc_p (var))) { FREE (value_cell (v)); if (array_p (var))