1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

typeset: Allow last numeric type given to be used (#221)

For most numeric types the last provided one wins out. This commit
closes the gap for -F and -i numerics to not be covered up by other
preceding float types. Note: -u for requesting an unsigned float or
integer was considered and decided to be left alone as it stands,
so as to not allow the variable to become an uppercased string if
the requested options ended with a -u. As it stands for a case when
multiple numeric types are requested, a -u option may be applied
after the last numeric type is processed.

Examples:
-EF becomes -F
-Fi becomes -i
-Fu becomes -F
-uF becomes -F
-Fui becomes -i  (because isfloat==1, unsigned is not applied)
-Fiu becomes -iu (isfloat is reset and allows unsigned to be set)

src/cmd/ksh93/bltins/typeset.c: b_typeset():
- Reset attribute bit flags for -E and -X when -F is requested by
  adding in NV_EXPNOTE to be removed.
- For -i option if a float precedes it, reset isfloat and -E/-F
  attribute bit flags.
- Take into account the impact of the shortint flag on floats.

src/cmd/ksh93/tests/attributes.sh:
- Add some validation tests to confirm that, when a -F follows
  either -E or -X, -F is used.
- Add some validation tests to confirm that, when -F/E/X precede
  a -i, the variable becomes an integer and not a float.
- Add in various tests when -s followed a float.
This commit is contained in:
hyenias 2021-03-16 06:19:00 -04:00 committed by GitHub
parent 1df6a82a8a
commit 4f9ce41aaa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 6 deletions

4
NEWS
View file

@ -8,6 +8,10 @@ Any uppercase BUG_* names are modernish shell bug IDs.
- If the HOME variable is unset, the bare tilde ~ now expands to the current
user's system-configured home directory instead of merely the username.
- Tighten up potential invalid typeset attribute combos when more than
one numeric type has been requested. In particular, -F and -i are no
longer masked over by previously given float types.
2021-03-13:
- Fixed a file descriptor leak that occurred when ksh used /dev/fd for

View file

@ -257,6 +257,11 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context)
else if (tdata.argnum==0)
tdata.argnum = NV_FLTSIZEZERO;
isfloat = 1;
if(shortint)
{
shortint = 0;
flag &= ~NV_INT16P;
}
if(n=='E')
{
flag &= ~NV_HEXFLOAT;
@ -268,8 +273,9 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context)
flag |= NV_HEXFLOAT;
}
else
/* n=='F' Remove possible collision with NV_UNSIGN/NV_HEXFLOAT */
flag &= ~NV_HEXFLOAT;
/* n=='F' Remove possible collision with NV_UNSIGN/NV_HEXFLOAT
and allow it to not be covered up by -E */
flag &= ~(NV_HEXFLOAT|NV_EXPNOTE);
break;
case 'b':
flag |= NV_BINARY;
@ -319,6 +325,11 @@ 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;
if(isfloat)
{
isfloat = 0;
flag &= ~(NV_HEXFLOAT|NV_EXPNOTE);
}
if(shortint)
{
flag &= ~NV_LONG;
@ -354,11 +365,14 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context)
break;
#endif /*SHOPT_TYPEDEF*/
case 's':
shortint=1;
if(flag&NV_INTEGER)
if(!isfloat)
{
flag &= ~NV_LONG;
flag |= NV_INT16P;
shortint=1;
if(flag&NV_INTEGER)
{
flag &= ~NV_LONG;
flag |= NV_INT16P;
}
}
break;
case 't':

View file

@ -589,6 +589,7 @@ got=$(< $tmpfile)
# ======
# Combining -u with -F or -E caused an incorrect variable type
# https://github.com/ksh93/ksh/pull/163
# Allow the last numeric type to win out
typeset -A expect=(
[uF]='typeset -F a=2.0000000000'
[Fu]='typeset -F a=2.0000000000'
@ -596,6 +597,20 @@ typeset -A expect=(
[Ful]='typeset -l -F a=2.0000000000'
[Eu]='typeset -E a=2'
[Eul]='typeset -l -E a=2'
[EF]='typeset -F a=2.0000000000'
[XF]='typeset -F a=2.0000000000'
[FE]='typeset -E a=2'
[XE]='typeset -E a=2'
[FX12]='typeset -X 12 a=0x1.000000000000p+1'
[EX12]='typeset -X 12 a=0x1.000000000000p+1'
[Fi]='typeset -i a=2'
[Ei]='typeset -i a=2'
[Xi]='typeset -i a=2'
[iF]='typeset -F a=2.0000000000'
[iFs]='typeset -F a=2.0000000000'
[iE]='typeset -E a=2'
[iEs]='typeset -E a=2'
[iX12]='typeset -X 12 a=0x1.000000000000p+1'
)
for flag in "${!expect[@]}"
do unset a
@ -612,6 +627,8 @@ do unset a
done
unset expect
[[ $(typeset -iX12 -s a=2; typeset -p a) == 'typeset -X 12 a=0x1.000000000000p+1' ]] || err_exit "typeset -iX12 -s failed to become typeset -X 12 a=0x1.000000000000p+1."
# ======
# Bug introduced in 0e4c4d61: could not alter the size of an existing justified string attribute
# https://github.com/ksh93/ksh/issues/142#issuecomment-780931533