mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-13 03:32:24 +00:00
typeset: fix short integer restriction (#166)
This commit corrects how shortint was being applied to various possible typeset variables in error. The short integer option modifier 'typeset -s' should only be able to be applied if the the variable is also an integer. Several issues were resolved with this fix: - 'typeset -s': created a short integer having an invalid base of zero. 'typeset -s foo' created 'typeset -s -i 0 foo=0' and now will result in an empty string. - 'typeset -sL': previously resulted in a segmentation fault. The following are the various incorrect 'typeset' instances that have been fixed: $ 'export foo; typeset -s foo; readonly foo; typeset -p foo' (before) typeset -x -r -s -i 0 foo=0 ( after) typeset -x -r foo $ 'typeset -sL foo=1*2; typeset -p foo' (before) Segmentation fault (core dumped) ( after) typeset -L 3 foo='1*2' $ 'typeset -sR foo=1*2; typeset -p foo' (before) typeset -s -i foo=2 ( after) typeset -R 3 foo='1*2' $ 'typeset -sZ foo=1*2; typeset -p foo' (before) typeset -F 0 foo=2 ( after) typeset -Z 3 -R 3 foo='1*2' src/cmd/ksh93/bltins/typeset.c: b_typeset(): - Add conditional check within the 's' option to only apply NV_SHORT as well as remove any NV_LONG flag if NV_INTEGER flag was set. - Relocate shortint conditional logic to the 'i' option. src/cmd/ksh93/tests/attributes.sh: - Adjust regression tests for '-s' and add '-si' check.
This commit is contained in:
parent
5491fe9724
commit
fe05350f2d
3 changed files with 18 additions and 7 deletions
4
NEWS
4
NEWS
|
@ -5,6 +5,10 @@ Any uppercase BUG_* names are modernish shell bug IDs.
|
|||
|
||||
2021-02-01:
|
||||
|
||||
- Fixed a bug in 'typeset': the '-s' modifier option for short integer will
|
||||
now only be applied if the integer option '-i' is also present, avoiding
|
||||
inconsistent results and a crash.
|
||||
|
||||
- Fixed: scalar arrays (-a) and associative arrays (-A) of a type created by
|
||||
'enum' allowed values not specified by the enum type, corrupting results.
|
||||
|
||||
|
|
|
@ -326,7 +326,13 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context)
|
|||
case 'i':
|
||||
if(!opt_info.arg || (tdata.argnum = opt_info.num) <2 || tdata.argnum >64)
|
||||
tdata.argnum = 10;
|
||||
flag |= NV_INTEGER;
|
||||
if(shortint)
|
||||
{
|
||||
flag &= ~NV_LONG;
|
||||
flag |= NV_SHORT|NV_INTEGER;
|
||||
}
|
||||
else
|
||||
flag |= NV_INTEGER;
|
||||
break;
|
||||
case 'l':
|
||||
tdata.wctname = e_tolower;
|
||||
|
@ -350,6 +356,11 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context)
|
|||
#endif /*SHOPT_TYPEDEF*/
|
||||
case 's':
|
||||
shortint=1;
|
||||
if(flag&NV_INTEGER)
|
||||
{
|
||||
flag &= ~NV_LONG;
|
||||
flag |= NV_SHORT;
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
flag |= NV_TAGGED;
|
||||
|
@ -426,11 +437,6 @@ endargs:
|
|||
errormsg(SH_DICT,ERROR_exit(2),"option argument cannot be greater than %d",SHRT_MAX);
|
||||
if(isfloat)
|
||||
flag |= NV_DOUBLE;
|
||||
if(shortint)
|
||||
{
|
||||
flag &= ~NV_LONG;
|
||||
flag |= NV_SHORT|NV_INTEGER;
|
||||
}
|
||||
if(sflag)
|
||||
{
|
||||
if(tdata.sh->mktype)
|
||||
|
|
|
@ -515,7 +515,8 @@ typeset -A expect=(
|
|||
[i37]='typeset -x -r -i 37 foo'
|
||||
[l]='typeset -x -r -l foo'
|
||||
[n]='typeset -n -r foo'
|
||||
[s]='typeset -x -r -s -i 0 foo=0'
|
||||
[s]='typeset -x -r foo'
|
||||
[si]='typeset -x -r -s -i foo=0'
|
||||
[u]='typeset -x -r -u foo'
|
||||
[A]='typeset -x -r -A foo=()'
|
||||
[C]='typeset -x -r foo=()'
|
||||
|
|
Loading…
Reference in a new issue