From 6a48b39bba066d6ce1e14dc86a864119aa1923d0 Mon Sep 17 00:00:00 2001
From: Chet Ramey
Date: Tue, 14 Oct 2025 14:21:00 -0400
Subject: [PATCH] read builtin fixes for CHERI environment; use CLOCK_GETTIME
in gettimeofday replacement; readline fix to not optimize typeahead while
defining a keyboard macro; fix for crash with unset nameref variable; make
sure to save currently executing command around running DEBUG trap
---
CWRU/CWRU.chlog | 46 ++++++++++++++++++++++++++++++++++++
builtins/declare.def | 15 ++++++++++--
builtins/mkbuiltins.c | 2 +-
builtins/read.def | 2 ++
doc/bash.0 | 23 ++++++++----------
doc/bash.1 | 16 ++++---------
doc/bash.html | 13 ++++------
doc/bash.pdf | Bin 441998 -> 441916 bytes
examples/loadables/cat.c | 2 +-
execute_cmd.c | 31 ++++++++++++++++++++++--
lib/readline/bind.c | 4 ++--
lib/readline/doc/history.3 | 13 +++-------
lib/readline/doc/readline.3 | 12 ++--------
lib/readline/histfile.c | 4 ++--
lib/readline/text.c | 2 +-
lib/sh/gettimeofday.c | 11 +++++++++
redir.c | 12 +---------
tests/glob2.sub | 9 ++++---
tests/nameref.right | 11 +++++----
tests/test-aux-functions | 21 ++++++++++++++++
tests/unicode1.sub | 11 +++++----
variables.c | 2 +-
22 files changed, 173 insertions(+), 89 deletions(-)
diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog
index 649451df..c5242654 100644
--- a/CWRU/CWRU.chlog
+++ b/CWRU/CWRU.chlog
@@ -11938,3 +11938,49 @@ builtins/read.def
- read_builtin: check whether `delim' is not a newline before calling
check_read_input
Report from pourko2@tutamail.com
+
+builtins/read.def
+ - read_builtin: CHERI systems require that we update the unwind-protect
+ after every xrealloc, not just if the pointer changes
+ From https://savannah.gnu.org/bugs/?67586
+
+ 10/7
+ ----
+doc/bash.1,lib/readline/doc/readline.3,lib/readline/doc/history.3
+ - remove mention of Usenet and gnu.bash.bug. End of an era.
+
+lib/sh/gettimeofday.c
+ - gettimeofday: if we're replacing this function on a non-Windows
+ system, prefer clock_gettime (CLOCK_REALTIME, ...) if it's available
+ instead of just filling in the seconds from time(3)
+
+ 10/9
+ ----
+lib/readline/text.c
+ - rl_insert: don't try to optimize runs of typeahead characters if we
+ are defining a keyboard macro
+ Report and patch from Grisha Levit
+
+ 10/12
+ -----
+variables.c
+ - make_variable_value: make sure to check whether VALUE is non-NULL
+ before trying to strdup it; not all callers check
+ Report from Александр Ушаков
+
+ 10/13riable`
+ -----
+builtins/declare.def
+ - declare_internal: if we are trying to set the attributes or value
+ for an unset nameref variable (attributes but no value), allow
+ the attribute or value setting to happen on the nameref, and don't
+ destroy the nameref variable on an assignment error
+ Report from Александр Ушаков
+
+execute_cmd.c
+ - execute_for_command,eval_arith_for_expr,execute_select_command,
+ execute_case_command,execute_arith_command,execute_cond_command,
+ execute_simple_command: save and restore currently_executing_command
+ around calls to run_debug_trap the same way we do it for
+ run_return_trap
+ Report from Александр Ушаков
diff --git a/builtins/declare.def b/builtins/declare.def
index b8c6f966..9aea47c8 100644
--- a/builtins/declare.def
+++ b/builtins/declare.def
@@ -775,10 +775,21 @@ restart_new_var_name:
*/
if (var == 0 && (mkglobal || flags_on || flags_off || offset))
{
- refvar = mkglobal ? find_global_variable_last_nameref (name, 0) : find_variable_last_nameref (name, 0);
+ refvar = mkglobal ? find_global_variable_last_nameref (name, 1) : find_variable_last_nameref (name, 1);
if (refvar && nameref_p (refvar) == 0)
refvar = 0;
- if (refvar)
+ /* If we are trying to set attributes for an unset nameref variable,
+ we have a couple of choices: we can set the attributes on the
+ nameref itself, or we can remove the nameref attribute from the
+ variable and treat it as an unset variable with the new
+ attribute(s). The former is what bash has traditionally done; the
+ latter is what ksh93 does. */
+ if (refvar && nameref_cell (refvar) == 0)
+ {
+ var = refvar;
+ refvar = 0;
+ }
+ if (refvar && nameref_cell (refvar))
var = declare_find_variable (nameref_cell (refvar), mkglobal, 0);
if (refvar && var == 0)
{
diff --git a/builtins/mkbuiltins.c b/builtins/mkbuiltins.c
index b39b9dd5..2a27826f 100644
--- a/builtins/mkbuiltins.c
+++ b/builtins/mkbuiltins.c
@@ -525,7 +525,7 @@ extract_info (char *filename, FILE *structfile, FILE *externfile)
if (stat (filename, &finfo) == -1)
file_error (filename);
- fd = open (filename, O_RDONLY, 0666);
+ fd = open (filename, O_RDONLY);
if (fd == -1)
file_error (filename);
diff --git a/builtins/read.def b/builtins/read.def
index 159bdb74..6b62d0be 100644
--- a/builtins/read.def
+++ b/builtins/read.def
@@ -817,7 +817,9 @@ read_builtin (WORD_LIST *list)
x = (char *)xrealloc (input_string, size += 128);
/* Only need to change unwind-protect if input_string changes */
+#ifndef __CHERI_PURE_CAPABILITY__
if (x != input_string)
+#endif
{
input_string = x;
remove_unwind_protect ();
diff --git a/doc/bash.0 b/doc/bash.0
index ecb970d0..da4d7d8f 100644
--- a/doc/bash.0
+++ b/doc/bash.0
@@ -7514,8 +7514,8 @@ BBUUGG RREEPPOORRTTSS
Once you have determined that a bug actually exists, use the _b_a_s_h_b_u_g
command to submit a bug report. If you have a fix, you are encouraged
to mail that as well! You may send suggestions and "philosophical" bug
- reports to or post them to the Usenet newsgroup ggnnuu
- ..bbaasshh..bbuugg.
+ reports, as well as comments and bug reports concerning this manual
+ page, to to .
_A_l_l bug reports should include:
@@ -7534,26 +7534,23 @@ BBUUGG RREEPPOORRTTSS
_b_a_s_h_b_u_g inserts the first three items automatically into the template
it provides for filing a bug report.
- Please send comments and bug reports concerning this manual page to
- .
-
BBUUGGSS
It's too big and too slow.
- There are some subtle differences between bbaasshh and historical versions
- of sshh, due mostly to bbaasshh's independent implementation and the evolu-
+ There are some subtle differences between bbaasshh and historical versions
+ of sshh, due mostly to bbaasshh's independent implementation and the evolu-
tion of the POSIX specification.
Aliases are confusing in some uses.
Shell builtin commands and functions are not stoppable/restartable.
- Compound commands and command lists of the form "a ; b ; c" are not
- handled gracefully when combined with process suspension. When a
- process is stopped, the shell immediately executes the next command in
- the list or breaks out of any existing loops. It suffices to enclose
- the command in parentheses to force it into a subshell, which may be
- stopped as a unit, or to start the command in the background and imme-
+ Compound commands and command lists of the form "a ; b ; c" are not
+ handled gracefully when combined with process suspension. When a
+ process is stopped, the shell immediately executes the next command in
+ the list or breaks out of any existing loops. It suffices to enclose
+ the command in parentheses to force it into a subshell, which may be
+ stopped as a unit, or to start the command in the background and imme-
diately bring it into the foreground.
Array variables may not (yet) be exported.
diff --git a/doc/bash.1 b/doc/bash.1
index b766d08a..ab307a86 100644
--- a/doc/bash.1
+++ b/doc/bash.1
@@ -13562,13 +13562,12 @@ command to submit a bug report.
If you have a fix, you are encouraged to mail that as well!
You may send suggestions and
.Q philosophical
-bug reports to
+bug reports,
+as well as comments and bug reports concerning this manual page,
+to
+to
.MT bug\-bash@\*:gnu\*:.org
-.ME
-or post them to the
-Usenet
-newsgroup
-.BR gnu\*:.bash\*:.bug .
+.ME .
.PP
.I All
bug reports should include:
@@ -13626,11 +13625,6 @@ exercising the unexpected behavior.
.I bashbug
inserts the first three items automatically into the template
it provides for filing a bug report.
-.PP
-Please send comments and bug reports concerning
-this manual page to
-.MT bug\-bash@\*:gnu\*:.org
-.ME .
.SH BUGS
It's too big and too slow.
.PP
diff --git a/doc/bash.html b/doc/bash.html
index e05e78d6..46a6da12 100644
--- a/doc/bash.html
+++ b/doc/bash.html
@@ -1,5 +1,5 @@
-
+
@@ -16375,9 +16375,10 @@ and
determined that a bug actually exists, use the
bashbug command to submit a bug report. If you have a
fix, you are encouraged to mail that as well! You may send
-suggestions and “philosophical” bug reports to
-bug-bash@gnu.org or
-post them to the Usenet newsgroup gnu.bash.bug.
+suggestions and “philosophical” bug reports, as
+well as comments and bug reports concerning this manual
+page, to to
+bug-bash@gnu.org.
All bug
reports should include:
@@ -16506,10 +16507,6 @@ the unexpected behavior.
inserts the first three items automatically into the
template it provides for filing a bug report.
-Please send
-comments and bug reports concerning this manual page to
-bug-bash@gnu.org.
-
BUGS
diff --git a/doc/bash.pdf b/doc/bash.pdf
index ae4ffc31effd0a67ccbfe10c4278ca0b076064ef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XJN&8
zC}fZ|9RQIL);^i@6MmxdJ19&W!rD7P#3QUN14Muoc?e*x$1gw1Z{!0^piu1-i3AoZ
znZYC!%1q2qR02d8L^p`QzvpAtXA()m!>Ga}0*neK0Wb;~5_4r(ks%TBXg?AGLiv#?
z1Xc+EB$$M527yq`knsqL5;6fn6(NIoR1Gpj_?ITx|7i~(6Y=OG@t>Yyg(ze)gc^tp
z6VZ7QGHRV*Jd9ci7+@7G1i&DGnj40|pSGVY{r5%yFcJEl!e0zB4+FXgQx~j=!|)&U
z{~L>-cb2*Czk&O+K66bFfP_L9VIBh3A_x&pHA4D5;eYax(X1jc2{jx-K~S`Ucsxp_
zARfT~*7dIOedZMJI?Sk$+M0yGlVk86|tBm{Af333vjlFhBx<
zz`7qG6KS*`_{RbNrBaZmMy1_?wGY7zno#XCrVQ8Y1eL5U9pmy0B7s#@AV5OH&r}~e7AE~0OZkmE0QvPkG0FX}B0#3XQNhgdP`dyEXzD-^
zwf!JSB>oZ0#2*4d=2c^b1|*aIaQx*5{~7$thM=i~m`lT&kNJF}@next ? string_list (l) : l->word->word;
temp = expand_arith_string (expr, Q_DOUBLE_QUOTES|Q_ARITH);
@@ -3206,7 +3211,10 @@ eval_arith_for_expr (WORD_LIST *l, int *okp)
the_printed_command_except_trap = savestring (the_printed_command);
}
+ save_current = currently_executing_command;
r = run_debug_trap ();
+ currently_executing_command = save_current;
+
#if defined (DEBUGGER)
/* In debugging mode, if the DEBUG trap returns a non-zero status, we
skip the command. */
@@ -3499,6 +3507,7 @@ execute_select_command (SELECT_COM *select_command)
SHELL_VAR *v;
char *identifier, *ps3_prompt, *selection;
int retval, list_len, show_menu, save_line_number;
+ COMMAND *save_current;
if (check_identifier (select_command->name, 1) == 0)
{
@@ -3526,7 +3535,10 @@ execute_select_command (SELECT_COM *select_command)
the_printed_command_except_trap = savestring (the_printed_command);
}
+ save_current = currently_executing_command;
retval = run_debug_trap ();
+ currently_executing_command = save_current;
+
#if defined (DEBUGGER)
/* In debugging mode, if the DEBUG trap returns a non-zero status, we
skip the command. */
@@ -3640,6 +3652,7 @@ execute_case_command (CASE_COM *case_command)
PATTERN_LIST *clauses;
char *word, *pattern;
int retval, match, ignore_return, save_line_number, qflags;
+ COMMAND *save_current;
save_line_number = line_number;
line_number = case_command->line;
@@ -3657,7 +3670,10 @@ execute_case_command (CASE_COM *case_command)
the_printed_command_except_trap = savestring (the_printed_command);
}
+ save_current = currently_executing_command;
retval = run_debug_trap();
+ currently_executing_command = save_current;
+
#if defined (DEBUGGER)
/* In debugging mode, if the DEBUG trap returns a non-zero status, we
skip the command. */
@@ -3877,6 +3893,7 @@ execute_arith_command (ARITH_COM *arith_command)
intmax_t expresult;
WORD_LIST *new;
char *exp, *t;
+ COMMAND *save_current;
expresult = 0;
@@ -3898,7 +3915,10 @@ execute_arith_command (ARITH_COM *arith_command)
/* Run the debug trap before each arithmetic command, but do it after we
update the line number information and before we expand the various
words in the expression. */
+ save_current = currently_executing_command;
retval = run_debug_trap ();
+ currently_executing_command = save_current;
+
#if defined (DEBUGGER)
/* In debugging mode, if the DEBUG trap returns a non-zero status, we
skip the command. */
@@ -4113,6 +4133,7 @@ static int
execute_cond_command (COND_COM *cond_command)
{
int retval, save_line_number;
+ COMMAND *save_current;
save_line_number = line_number;
@@ -4131,7 +4152,10 @@ execute_cond_command (COND_COM *cond_command)
/* Run the debug trap before each conditional command, but do it after we
update the line number information. */
+ save_current = currently_executing_command;
retval = run_debug_trap ();
+ currently_executing_command = save_current;
+
#if defined (DEBUGGER)
/* In debugging mode, if the DEBUG trap returns a non-zero status, we
skip the command. */
@@ -4455,6 +4479,7 @@ execute_simple_command (SIMPLE_COM *simple_command, int pipe_in, int pipe_out, i
pid_t old_last_async_pid;
sh_builtin_func_t *builtin;
SHELL_VAR *func;
+ COMMAND *save_current;
volatile int old_builtin, old_command_builtin;
result = EXECUTION_SUCCESS;
@@ -4484,7 +4509,10 @@ execute_simple_command (SIMPLE_COM *simple_command, int pipe_in, int pipe_out, i
/* Run the debug trap before each simple command, but do it after we
update the line number information. */
+ save_current = currently_executing_command;
result = run_debug_trap ();
+ currently_executing_command = save_current;
+
#if defined (DEBUGGER)
/* In debugging mode, if the DEBUG trap returns a non-zero status, we
skip the command. */
@@ -5396,13 +5424,13 @@ execute_function (SHELL_VAR *var, WORD_LIST *words, int flags, struct fd_bitmap
showing_function_line = 1;
save_current = currently_executing_command;
result = run_debug_trap ();
+ currently_executing_command = save_current;
#if defined (DEBUGGER)
/* In debugging mode, if the DEBUG trap returns a non-zero status, we
skip the command. */
if (debugging_mode == 0 || result == EXECUTION_SUCCESS)
{
showing_function_line = 0;
- currently_executing_command = save_current;
result = execute_command_internal (fc, 0, NO_PIPE, NO_PIPE, fds_to_close);
/* Run the RETURN trap in the function's context */
@@ -5411,7 +5439,6 @@ execute_function (SHELL_VAR *var, WORD_LIST *words, int flags, struct fd_bitmap
currently_executing_command = save_current;
}
#else
- currently_executing_command = save_current;
result = execute_command_internal (fc, 0, NO_PIPE, NO_PIPE, fds_to_close);
save_current = currently_executing_command;
diff --git a/lib/readline/bind.c b/lib/readline/bind.c
index 6aaa6374..6df53045 100644
--- a/lib/readline/bind.c
+++ b/lib/readline/bind.c
@@ -967,12 +967,12 @@ _rl_read_file (char *filename, size_t *sizep)
char *buffer;
int i, file;
- file = open (filename, O_RDONLY, 0666);
+ file = open (filename, O_RDONLY);
/* If the open is interrupted, retry once */
if (file < 0 && errno == EINTR)
{
RL_CHECK_SIGNALS ();
- file = open (filename, O_RDONLY, 0666);
+ file = open (filename, O_RDONLY);
}
if ((file < 0) || (fstat (file, &finfo) < 0))
diff --git a/lib/readline/doc/history.3 b/lib/readline/doc/history.3
index 9acf75d4..516db919 100644
--- a/lib/readline/doc/history.3
+++ b/lib/readline/doc/history.3
@@ -833,15 +833,8 @@ bug report to
If you have a fix, you are welcome to mail that as well!
Please send suggestions and
.Q philosophical
-bug reports to
-.MT bug\-readline@\*:gnu\*:.org
-.ME
-or post them to the
-Usenet
-newsgroup
-.BR gnu\*:.bash\*:.bug .
-.PP
-Please send comments and bug reports concerning
-this manual page to
+bug reports,
+as well as comments and bug reports concerning this manual page,
+to
.MT bug\-readline@\*:gnu\*:.org
.ME .
diff --git a/lib/readline/doc/readline.3 b/lib/readline/doc/readline.3
index e748f46f..1466b560 100644
--- a/lib/readline/doc/readline.3
+++ b/lib/readline/doc/readline.3
@@ -1923,16 +1923,8 @@ bug report to
If you have a fix, you are welcome to mail that as well!
Please send suggestions and
.Q philosophical
-bug reports
+bug reports,
+as well as comments and bug reports concerning this manual page,
to
.MT bug\-readline@\*:gnu\*:.org
-.ME
-or post them to the
-Usenet
-newsgroup
-.BR gnu\*:.bash\*:.bug .
-.PP
-Please send comments and bug reports concerning
-this manual page to
-.MT bug\-readline@\*:gnu\*:.org
.ME .
diff --git a/lib/readline/histfile.c b/lib/readline/histfile.c
index 235243c3..f7539783 100644
--- a/lib/readline/histfile.c
+++ b/lib/readline/histfile.c
@@ -354,7 +354,7 @@ read_history_range (const char *filename, int from, int to)
if (input == 0)
return 0;
errno = 0;
- file = open (input, O_RDONLY|O_BINARY, 0666);
+ file = open (input, O_RDONLY|O_BINARY);
if ((file < 0) || (fstat (file, &finfo) == -1))
goto error_and_exit;
@@ -623,7 +623,7 @@ history_truncate_file (const char *fname, int lines)
if (filename == 0)
return 0;
tempname = 0;
- file = open (filename, O_RDONLY|O_BINARY, 0666);
+ file = open (filename, O_RDONLY|O_BINARY);
rv = exists = 0;
orig_lines = lines;
diff --git a/lib/readline/text.c b/lib/readline/text.c
index 9b00a6f1..72baf331 100644
--- a/lib/readline/text.c
+++ b/lib/readline/text.c
@@ -994,7 +994,7 @@ rl_insert (int count, int c)
n = (unsigned short)-2;
while (_rl_optimize_typeahead &&
rl_num_chars_to_read == 0 &&
- (RL_ISSTATE (RL_STATE_INPUTPENDING|RL_STATE_MACROINPUT) == 0) &&
+ (RL_ISSTATE (RL_STATE_INPUTPENDING|RL_STATE_MACROINPUT|RL_STATE_MACRODEF) == 0) &&
_rl_pushed_input_available () == 0 &&
_rl_input_queued (0) &&
(n = rl_read_key ()) > 0 &&
diff --git a/lib/sh/gettimeofday.c b/lib/sh/gettimeofday.c
index 76b16573..29ed8d89 100644
--- a/lib/sh/gettimeofday.c
+++ b/lib/sh/gettimeofday.c
@@ -119,6 +119,17 @@ gettimeofday (struct timeval *restrict tv, void *restrict tz)
return 0;
#else /* !WINDOWS_NATIVE */
+# if defined (HAVE_CLOCK_GETTIME) && defined (CLOCK_REALTIME)
+ struct timespec ts;
+ int r;
+
+ r = clock_gettime (CLOCK_REALTIME, &ts);
+ if (r == 0)
+ {
+ TIMESPEC_TO_TIMEVAL(tv, &ts);
+ return 0;
+ }
+# endif /* !CLOCK_GETTIME */
tv->tv_sec = (time_t) time ((time_t *)0);
tv->tv_usec = 0;
diff --git a/redir.c b/redir.c
index 343536b7..3083a163 100644
--- a/redir.c
+++ b/redir.c
@@ -522,7 +522,7 @@ use_tempfile:
/* In an attempt to avoid races, we close the first fd only after opening
the second. */
/* Make the document really temporary. Also make it the input. */
- fd2 = open (filename, O_RDONLY|O_BINARY, 0600);
+ fd2 = open (filename, O_RDONLY|O_BINARY);
if (fd2 < 0)
{
@@ -729,16 +729,6 @@ redir_open (char *filename, int flags, int mode, enum r_instruction ri)
errno = e;
}
while (fd < 0 && errno == EINTR);
-
-#if 0 /* reportedly no longer needed */
-#if defined (AFS)
- if ((fd < 0) && (errno == EACCES))
- {
- fd = open (filename, flags & ~O_CREAT, mode);
- errno = EACCES; /* restore errno */
- }
-#endif /* AFS */
-#endif
}
return fd;
diff --git a/tests/glob2.sub b/tests/glob2.sub
index c5263775..7c795c98 100644
--- a/tests/glob2.sub
+++ b/tests/glob2.sub
@@ -14,11 +14,10 @@
. ./test-aux-functions
# this locale causes problems all over the place
-if locale -a | grep -i '^zh_TW\.big5' >/dev/null ; then
- :
-else
+if [ -z "$ZH_LOCALE" ]; then
echo "glob2.sub: warning: you do not have the zh_TW.big5 locale installed;" >&2
echo "glob2.sub: warning: that may cause some of these tests to fail." >&2
+ ZH_LOCALE=$ZH_DEFAULT
fi
var='ab\'
@@ -41,7 +40,7 @@ esac
[[ $var = $var ]] && echo ok 4
[[ $var = $'ab\134' ]] && echo ok 5
-LC_ALL=zh_TW.big5
+LC_ALL=$ZH_LOCALE
read a b c <<< $'\u3b1 b c\n'
echo $b
@@ -62,4 +61,4 @@ printf "%s" "a${alpha}b" | LC_ALL=C od -b | _intl_normalize_spaces
a=$'\u3b1'
[[ $a = $a ]] && echo ok 6
-LC_ALL=zh_TW.big5 ${THIS_SH} -c $'[[ \u3b1 = \u3b1 ]]' && echo ok 7
+LC_ALL=${ZH_LOCALE} ${THIS_SH} -c $'[[ \u3b1 = \u3b1 ]]' && echo ok 7
diff --git a/tests/nameref.right b/tests/nameref.right
index 19259fce..ec424e0f 100644
--- a/tests/nameref.right
+++ b/tests/nameref.right
@@ -183,7 +183,7 @@ declare -n foo="bar"
./nameref11.sub: line 14: declare: `/': invalid variable name for name reference
./nameref11.sub: line 15: declare: `/': invalid variable name for name reference
./nameref11.sub: line 16: `/': not a valid identifier
-./nameref11.sub: line 17: declare: `/': not a valid identifier
+./nameref11.sub: line 17: declare: `/': invalid variable name for name reference
./nameref11.sub: line 18: `/': not a valid identifier
1) /
#? ./nameref11.sub: line 19: `/': not a valid identifier
@@ -243,12 +243,12 @@ declare -r RO2="a"
declare -n r
declare -a foo
declare -a foo=([0]="7")
-./nameref12.sub: line 39: declare: `42': not a valid identifier
-./nameref12.sub: line 40: declare: x: not found
+./nameref12.sub: line 39: declare: `42': invalid variable name for name reference
+declare -n x
declare -nr RO="foo"
/
-./nameref12.sub: line 58: declare: `7*6': not a valid identifier
-./nameref12.sub: line 58: declare: foo: not found
+./nameref12.sub: line 58: declare: `7*6': invalid variable name for name reference
+declare -n foo
./nameref12.sub: line 60: `7*6': not a valid identifier
declare -n ref="var"
declare -n ref="var"
@@ -381,6 +381,7 @@ declare -- bar
./nameref17.sub: line 28: declare: foo0: readonly variable
declare -nr foo1
./nameref17.sub: line 37: typeset: foo1: readonly variable
+./nameref17.sub: line 38: typeset: foo1: readonly variable
declare -nr foo1
declare -n foo2="bar"
declare -r bar
diff --git a/tests/test-aux-functions b/tests/test-aux-functions
index 2423eebb..869cb304 100644
--- a/tests/test-aux-functions
+++ b/tests/test-aux-functions
@@ -19,3 +19,24 @@ test_runsub()
${THIS_SH} "$1"
}
+
+# some useful locale variables
+ZH_LOCALE=$(locale -a | grep -i '^zh_TW\.big5' | sed 1q)
+ZH_DEFAULT=$(locale | grep ^LC_CTYPE | sed 's:^.*=::' | tr -d '"')
+
+US_LOCALE=$(locale -a | grep -i '^en_US\.utf-8' | sed 1q)
+if [ -z "$US_LOCALE" ]; then
+ US_LOCALE=$(locale -a | grep -i '^en_US\.utf8' | sed 1q)
+fi
+CTYPE_DEFAULT=$ZH_DEFAULT
+
+# figure out default locale; use LC_CTYPE value since that is what we use it for
+if [ -n "$LC_ALL" ]; then
+ DEFAULT_LOCALE=${LC_ALL}
+elif [ -n "$LC_CTYPE" ]; then
+ DEFAULT_LOCALE=${LC_CTYPE}
+elif [ -n "$LANG" ]; then
+ DEFAULT_LOCALE=${LANG}
+else
+ DEFAULT_LOCALE="C"
+fi
diff --git a/tests/unicode1.sub b/tests/unicode1.sub
index 2a70247b..a1da45a1 100644
--- a/tests/unicode1.sub
+++ b/tests/unicode1.sub
@@ -19,6 +19,8 @@ unset LC_ALL
ErrorCnt=0
TestCnt=0
+. ./test-aux-functions
+
localewarn()
{
echo "unicode1.sub: warning: you do not have the $1 locale installed;" >&2
@@ -98,8 +100,9 @@ fr_FR_ISO_8859_1=(
)
# this locale causes problems all over the place
-if locale -a | grep -i '^fr_FR\.ISO8859.*1$' >/dev/null ; then
- TestCodePage fr_FR.ISO8859-1 fr_FR_ISO_8859_1
+FR_LOCALE=$(locale -a | grep -i '^fr_FR\.ISO8859-1' | sed 1q)
+if [ -n "$FR_LOCALE" ]; then
+ TestCodePage ${FR_LOCALE} fr_FR_ISO_8859_1
else
localewarn fr_FR.ISO8859-1
@@ -118,8 +121,8 @@ zh_TW_BIG5=(
)
# this locale causes problems all over the place
-if locale -a | grep -i '^zh_TW\.big5' >/dev/null ; then
- TestCodePage zh_TW.BIG5 zh_TW_BIG5
+if [ -n "$ZH_LOCALE" ]; then
+ TestCodePage $ZH_LOCALE zh_TW_BIG5
else
localewarn zh_TW.BIG5
fi
diff --git a/variables.c b/variables.c
index 214760f4..7f1449d1 100644
--- a/variables.c
+++ b/variables.c
@@ -2971,7 +2971,7 @@ make_variable_value (SHELL_VAR *var, const char *value, int flags)
if (value)
strcpy (retval+olen, value);
}
- else if (*value)
+ else if (value && *value)
retval = savestring (value);
else
{