From 661f4c20c386d25bf60ec8792b28d124184bd8c0 Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Mon, 29 Jan 2018 08:55:47 -0500 Subject: [PATCH] commit bash-20180126 snapshot --- CWRU/CWRU.chlog | 36 ++++++++++++++++++++++++++++++++++++ arrayfunc.c | 9 ++++++++- bashline.c | 14 ++++++++++++-- builtins/history.def | 6 ++++-- doc/bash.1 | 7 ++++--- doc/bashref.texi | 3 ++- doc/version.texi | 4 ++-- execute_cmd.c | 5 ++++- general.c | 2 ++ lib/readline/display.c | 33 +++++++++++++++++++++++++-------- 10 files changed, 99 insertions(+), 20 deletions(-) diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 5962116b..545a6137 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -14866,3 +14866,39 @@ lib/readline/rltty.c bound to the VDISCARD character in the current keymap, set VDISCARD to _POSIX_VDISABLE while readline is active. From a report from Rhialto + + 1/22 + ---- +builtins/history.def + - histtime: check whether or not localtime() returns NULL, and make + sure we only call strftime() with a valid struct tm. This can happen + when the timestamps in the history file overflow a time_t. Fixes bug + reported by Luke Dashjr + +bashline.c + - edit_and_execute_command: if we're in vi editing mode, make sure + we end up in insert mode after executing the commands from the + edited file. This seems to be what other shells do. Report from + Stan Marsh + + 1/26 + ---- +bashline.c + - command_word_completion_function: match alias and shell function + names case-insensitively if the readline completion-ignore-case + variable is set. Inspired by report from + +lib/readline/display.c + - update_line: when performing a dumb update after wrapping the line + (usually due to printing the prompt), make sure we adjust + _rl_last_c_pos if there are invisible characters in prompt lines + other than the first (we assume those invisible characters are in + the last line, which is nearly always the case). We adjust by the + total number of invisible chars less the number of invisible chars + in the first prompt line. From a report in + https://bugs.launchpad.net/ubuntu/+source/bash/+bug/1745273 + +execute_cmd.c + - execute_command_internal: if redirections attached to a compound + command fail, make sure we discard the `internal_fifos' unwind- + protect frame after freeing the copied fifo_list and before returning diff --git a/arrayfunc.c b/arrayfunc.c index 752e1efa..a7c7ec1e 100644 --- a/arrayfunc.c +++ b/arrayfunc.c @@ -902,16 +902,23 @@ valid_array_reference (name, flags) *t = '['; if (r == 0) return 0; - /* Check for a properly-terminated non-blank subscript. */ + /* Check for a properly-terminated non-null subscript. */ len = skipsubscript (t, 0, flags); if (t[len] != ']' || len == 1) return 0; if (t[len+1] != '\0') return 0; +#if 1 + /* Could check and allow subscripts consisting only of whitespace for + existing associative arrays. */ for (r = 1; r < len; r++) if (whitespace (t[r]) == 0) return 1; return 0; +#else + /* This allows blank subscripts */ + return 1; +#endif } return 0; } diff --git a/bashline.c b/bashline.c index f2369d1a..5683d915 100644 --- a/bashline.c +++ b/bashline.c @@ -992,6 +992,11 @@ edit_and_execute_command (count, c, editing_mode, edit_command) rl_done = 0; rl_readline_state = rrs; +#if defined (VI_MODE) + if (editing_mode == VI_EDITING_MODE) + rl_vi_insertion_mode (1, c); +#endif + rl_forced_update_display (); return r; @@ -1942,7 +1947,9 @@ command_word_completion_function (hint_text, state) alias = alias_list[local_index++]->name; - if (STREQN (alias, hint, hint_len)) + if (igncase == 0 && (STREQN (alias, hint, hint_len))) + return (savestring (alias)); + else if (igncase && strncasecmp (alias, hint, hint_len) == 0) return (savestring (alias)); } #endif /* ALIAS */ @@ -1971,7 +1978,10 @@ command_word_completion_function (hint_text, state) varname = varlist[local_index++]->name; - if (STREQN (varname, hint, hint_len)) + /* Honor completion-ignore-case for shell function names. */ + if (igncase == 0 && (STREQN (varname, hint, hint_len))) + return (savestring (varname)); + else if (igncase && strncasecmp (varname, hint, hint_len) == 0) return (savestring (varname)); } local_index = 0; diff --git a/builtins/history.def b/builtins/history.def index b2bf66ab..77093a45 100644 --- a/builtins/history.def +++ b/builtins/history.def @@ -321,10 +321,12 @@ histtime (hlist, histtimefmt) { static char timestr[128]; time_t t; + struct tm *tm; t = history_get_time (hlist); - if (t) - strftime (timestr, sizeof (timestr), histtimefmt, localtime (&t)); + tm = t ? localtime (&t) : 0; + if (t && tm) + strftime (timestr, sizeof (timestr), histtimefmt, tm); else if (hlist->timestamp && hlist->timestamp[0]) snprintf (timestr, sizeof (timestr), _("%s: invalid timestamp"), (hlist->timestamp[0] == '#') ? hlist->timestamp + 1: hlist->timestamp); diff --git a/doc/bash.1 b/doc/bash.1 index 544b07cd..1c72510a 100644 --- a/doc/bash.1 +++ b/doc/bash.1 @@ -5,12 +5,12 @@ .\" Case Western Reserve University .\" chet.ramey@case.edu .\" -.\" Last Change: Thu Jan 4 15:29:06 EST 2018 +.\" Last Change: Thu Jan 25 10:51:45 EST 2018 .\" .\" bash_builtins, strip all but Built-Ins section .if \n(zZ=1 .ig zZ .if \n(zY=1 .ig zY -.TH BASH 1 "2018 January 4" "GNU Bash 4.4" +.TH BASH 1 "2018 January 25" "GNU Bash 4.4" .\" .\" There's some problem with having a `@' .\" in a tagged paragraph with the BSD man macros. @@ -963,7 +963,8 @@ command (see below). The file descriptors can be utilized as arguments to shell commands and redirections using standard word expansions. -The file descriptors are not available in subshells. +Other than those created to execute command and process substitutions, +the file descriptors are not available in subshells. The process ID of the shell spawned to execute the coprocess is available as the value of the variable \fINAME\fP_PID. The \fBwait\fP diff --git a/doc/bashref.texi b/doc/bashref.texi index 80a6930e..cf02af6b 100644 --- a/doc/bashref.texi +++ b/doc/bashref.texi @@ -1208,7 +1208,8 @@ This pipe is established before any redirections specified by the command (@pxref{Redirections}). The file descriptors can be utilized as arguments to shell commands and redirections using standard word expansions. -The file descriptors are not available in subshells. +Other than those created to execute command and process substitutions, +the file descriptors are not available in subshells. The process ID of the shell spawned to execute the coprocess is available as the value of the variable @env{NAME}_PID. diff --git a/doc/version.texi b/doc/version.texi index f44aa102..b934a1a3 100644 --- a/doc/version.texi +++ b/doc/version.texi @@ -2,10 +2,10 @@ Copyright (C) 1988-2018 Free Software Foundation, Inc. @end ignore -@set LASTCHANGE Thu Jan 4 15:30:21 EST 2018 +@set LASTCHANGE Thu Jan 25 10:51:29 EST 2018 @set EDITION 4.4 @set VERSION 4.4 -@set UPDATED 4 January 2018 +@set UPDATED 25 January 2018 @set UPDATED-MONTH January 2018 diff --git a/execute_cmd.c b/execute_cmd.c index 9170aab2..f608429f 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -764,7 +764,10 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out, dispose_exec_redirects (); #if defined (PROCESS_SUBSTITUTION) if (saved_fifo) - free ((void *)ofifo_list); + { + free ((void *)ofifo_list); + discard_unwind_frame ("internal_fifos"); + } #endif return (last_command_exit_value = EXECUTION_FAILURE); } diff --git a/general.c b/general.c index adef2d8f..b1598621 100644 --- a/general.c +++ b/general.c @@ -380,6 +380,8 @@ assignment (string, flags) if (c == '[') { newi = skipsubscript (string, indx, (flags & 2) ? 1 : 0); + /* XXX - why not check for blank subscripts here, if we do in + valid_array_reference? */ if (string[newi++] != ']') return (0); if (string[newi] == '+' && string[newi+1] == '=') diff --git a/lib/readline/display.c b/lib/readline/display.c index 54566efd..5b2663a8 100644 --- a/lib/readline/display.c +++ b/lib/readline/display.c @@ -1168,11 +1168,12 @@ rl_redisplay (void) wrap_offset. */ if (linenum == 0 && (mb_cur_max > 1 && rl_byte_oriented == 0) && OLD_CPOS_IN_PROMPT()) _rl_last_c_pos -= prompt_invis_chars_first_line; /* XXX - was wrap_offset */ - else if (linenum == prompt_last_screen_line && prompt_physical_chars > _rl_screenwidth && + else if (linenum == prompt_last_screen_line && + prompt_physical_chars > _rl_screenwidth && (mb_cur_max > 1 && rl_byte_oriented == 0) && cpos_adjusted == 0 && _rl_last_c_pos != o_cpos && - _rl_last_c_pos > (prompt_last_invisible - _rl_screenwidth - prompt_invis_chars_first_line)) + _rl_last_c_pos > (prompt_last_invisible - _rl_screenwidth - prompt_invis_chars_first_line)) /* XXX - rethink this last one */ /* This assumes that all the invisible characters are split between the first and last lines of the prompt, if the prompt consumes more than two lines. It's usually right */ @@ -1896,7 +1897,23 @@ dumb_update: { _rl_output_some_chars (nfd, temp); if (mb_cur_max > 1 && rl_byte_oriented == 0) - _rl_last_c_pos += _rl_col_width (new, nd, ne - new, 1); + { + _rl_last_c_pos += _rl_col_width (new, nd, ne - new, 1); + /* Need to adjust here based on wrap_offset. Guess that if + this is the line containing the last line of the prompt + we need to adjust by + wrap_offset-prompt_invis_chars_first_line + on the assumption that this is the number of invisible + characters in the last line of the prompt. */ + if (wrap_offset > prompt_invis_chars_first_line && + current_line == prompt_last_screen_line && + prompt_physical_chars > _rl_screenwidth && + _rl_horizontal_scroll_mode == 0) + { + _rl_last_c_pos -= wrap_offset - prompt_invis_chars_first_line; + cpos_adjusted = 1; + } + } else _rl_last_c_pos += temp; } @@ -1987,7 +2004,7 @@ dumb_update: cpos_adjusted to let the caller know. */ if (current_line == 0 && displaying_prompt_first_line && wrap_offset && ((nfd - new) <= prompt_last_invisible)) { - _rl_last_c_pos -= wrap_offset; + _rl_last_c_pos -= wrap_offset; /* XXX - prompt_invis_chars_first_line? */ cpos_adjusted = 1; } return; @@ -2040,7 +2057,7 @@ dumb_update: and set cpos_adjusted to let the caller know. */ if ((mb_cur_max > 1 && rl_byte_oriented == 0) && current_line == 0 && displaying_prompt_first_line && wrap_offset && ((nfd - new) <= prompt_last_invisible)) { - _rl_last_c_pos -= wrap_offset; + _rl_last_c_pos -= wrap_offset; /* XXX - prompt_invis_chars_first_line? */ cpos_adjusted = 1; } return; @@ -2053,7 +2070,7 @@ dumb_update: and set cpos_adjusted to let the caller know. */ if ((mb_cur_max > 1 && rl_byte_oriented == 0) && current_line == 0 && displaying_prompt_first_line && wrap_offset && ((nfd - new) <= prompt_last_invisible)) { - _rl_last_c_pos -= wrap_offset; + _rl_last_c_pos -= wrap_offset; /* XXX - prompt_invis_chars_first_line? */ cpos_adjusted = 1; } } @@ -2123,7 +2140,7 @@ dumb_update: _rl_last_c_pos >= wrap_offset && /* XXX was > */ ((nfd - new) <= prompt_last_invisible)) { - _rl_last_c_pos -= wrap_offset; + _rl_last_c_pos -= wrap_offset; /* XXX - prompt_invis_chars_first_line? */ cpos_adjusted = 1; } @@ -2171,7 +2188,7 @@ dumb_update: _rl_last_c_pos > wrap_offset && ((nfd - new) <= prompt_last_invisible)) { - _rl_last_c_pos -= wrap_offset; + _rl_last_c_pos -= wrap_offset; /* XXX - prompt_invis_chars_first_line? */ cpos_adjusted = 1; } }