From 0e4c4d619d91f0fcbcfe7841178b167c3af1ee2a Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Mon, 1 Feb 2021 23:49:02 +0000 Subject: [PATCH] Fix minor typeset attribute regressions (re: 95fe07d8, fdb9781e) This fixes the following regressions marked TODO in attributes.sh: $ typeset -L 13 bar; readonly bar; typeset -p bar typeset -r -L 0 foo # exp.: typeset -r -L 13 foo $ typeset -R 13 bar; readonly bar; typeset -p bar typeset -r -R 0 bar # exp.: typeset -r -R 13 bar $ typeset -Z 13 baz; readonly baz; typeset -p baz typeset -r -Z 0 -R 0 baz # exp.: typeset -r Z 13 -R 13 baz I've discovered that these were briefly fixed between fdb9781e (Red Hat patch for typeset -xu/-xl) and 95fe07d8 (reversal of patch, different -xu/-xl fix, but reintroduced these regressions). src/cmd/ksh93/sh/name.c: nv_newattr(): - Replace check from 95fe07d8 with a new one that combines its approach with that of fdb9781e: do not change size (and hence return early) if NV_RDONLY and/or NV_EXPORT are the only attributes that are changing. src/cmd/ksh93/tests/attributes.sh: - Enable the TODO regression tests. --- src/cmd/ksh93/sh/name.c | 5 ++--- src/cmd/ksh93/tests/attributes.sh | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/cmd/ksh93/sh/name.c b/src/cmd/ksh93/sh/name.c index 4a0b0667c4fc..7e4487a9a99d 100644 --- a/src/cmd/ksh93/sh/name.c +++ b/src/cmd/ksh93/sh/name.c @@ -2966,11 +2966,10 @@ void nv_newattr (register Namval_t *np, unsigned newatts, int size) nv_onattr(np,NV_EXPORT); sh_envput(shp->env,np); } - if((n^newatts)==NV_EXPORT && !trans) - /* Only EXPORT attribute has changed and thus all work has been done. */ - return; } oldsize = nv_size(np); + if(((n^newatts) & ~(NV_EXPORT|NV_RDONLY))==0) + size = oldsize; if((size==oldsize|| (n&NV_INTEGER)) && !trans && ((n^newatts)&~NV_NOCHANGE)==0) { if(size>0) diff --git a/src/cmd/ksh93/tests/attributes.sh b/src/cmd/ksh93/tests/attributes.sh index 064b0e33a836..5e92634b8b51 100755 --- a/src/cmd/ksh93/tests/attributes.sh +++ b/src/cmd/ksh93/tests/attributes.sh @@ -526,16 +526,16 @@ typeset -A expect=( [F12]='typeset -x -r -F 12 foo' [H]='typeset -x -r -H foo' [L]='typeset -x -r -L 0 foo' -# [L17]='typeset -x -r -L 17 foo' # TODO: outputs '-L 0' + [L17]='typeset -x -r -L 17 foo' [Mtolower]='typeset -x -r -l foo' [Mtoupper]='typeset -x -r -u foo' [R]='typeset -x -r -R 0 foo' -# [R17]='typeset -x -r -R 17 foo' # TODO: outputs '-L 0' + [R17]='typeset -x -r -R 17 foo' [X17]='typeset -x -r -X 17 foo' [S]='typeset -x -r foo' [T]='typeset -x -r foo' [Z]='typeset -x -r -Z 0 -R 0 foo' -# [Z13]='typeset -x -r -Z 13 -R 13 foo' # TODO: outputs 'typeset -x -r -Z 0 -R 0 foo' + [Z13]='typeset -x -r -Z 13 -R 13 foo' ) for flag in "${!expect[@]}" do unset foo