Skip to content

Commit

Permalink
Revert 0e4c4d6 ("Fix minor typeset attribute regressions")
Browse files Browse the repository at this point in the history
This commit introduced the following bug, which is worse than the
one that commit fixed: it became impossible to alter the size of an
existing justified string attribute.

Thanks to @hyenias for catching this bug:
#142 (comment)

$ unset s; typeset -L 100 s=h; typeset +p s; typeset -L 5 s; typeset +p s
typeset -L 100 s
typeset -L 100 s

Expected output:
typeset -L 100 s
typeset -L 5 s

src/cmd/ksh93/sh/name.c:
- Revert.

src/cmd/ksh93/tests/attributes.sh:
- Revert: re-disable tests for minor attribute output regressions.
- Add a test for this bug and potential similar bugs.
  • Loading branch information
McDutchie committed Feb 18, 2021
1 parent 241b5a4 commit 50b665b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/cmd/ksh93/sh/name.c
Original file line number Diff line number Diff line change
Expand Up @@ -2985,10 +2985,11 @@ 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)
Expand Down
21 changes: 18 additions & 3 deletions src/cmd/ksh93/tests/attributes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
# [L17]='typeset -x -r -L 17 foo' # TODO: outputs '-L 0'
[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'
# [R17]='typeset -x -r -R 17 foo' # TODO: outputs '-L 0'
[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'
# [Z13]='typeset -x -r -Z 13 -R 13 foo' # TODO: outputs 'typeset -x -r -Z 0 -R 0 foo'
)
for flag in "${!expect[@]}"
do unset foo
Expand Down Expand Up @@ -614,5 +614,20 @@ do unset a
done
unset expect

# ======
# https://github.com/ksh93/ksh/issues/142#issuecomment-780931533
got=$(unset s; typeset -L 100 s=h; typeset +p s; typeset -L 5 s; typeset +p s)
exp=$'typeset -L 100 s\ntypeset -L 5 s'
[[ $got == "$exp" ]] || err_exit 'cannot alter size of existing justified string attribute' \
"expected $(printf %q "$exp"), got $(printf %q "$got")"
got=$(unset s; typeset -L 100 s=h; typeset +p s; typeset -R 5 s; typeset +p s)
exp=$'typeset -L 100 s\ntypeset -R 5 s'
[[ $got == "$exp" ]] || err_exit 'cannot set -R after setting -L' \
"expected $(printf %q "$exp"), got $(printf %q "$got")"
got=$(unset s; typeset -L 100 s=h; typeset +p s; typeset -Z 5 s; typeset +p s)
exp=$'typeset -L 100 s\ntypeset -Z 5 -R 5 s'
[[ $got == "$exp" ]] || err_exit 'cannot set -Z after setting -L' \
"expected $(printf %q "$exp"), got $(printf %q "$got")"

# ======
exit $((Errors<125?Errors:125))

1 comment on commit 50b665b

@hyenias
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am working on correcting the referenced outstanding TODOs. In fact, I am testing a fix at this moment.

Please sign in to comment.