mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Correctly block invalid values for arrays of an enum type
This fixes part of https://github.com/ksh93/ksh/issues/87: Scalar arrays (-a) and associative arrays (-A) of a type created by 'enum' did not consistently block values not specified by the enum type, yielding corrupted results. An expansion of type "${array[@]}" yielded random numbers instead of values for associative arrays of a type created by 'enum'. This does not yet fix another problem: ${array[@]} does not yield all values for associative enum arrays. src/cmd/ksh93/bltins/enum.c: put_enum(): - Always throw an error if the value is not in the list of possible values for an enum type. Remove incorrect check for the NV_NOFREE flag. Whatever that was meant to accomplish, I've no idea. src/cmd/ksh93/sh/array.c: nv_arraysettype(): - Instead of sh_eval()ing a shell assignment, use nv_putval() directly. Also use the stack (see src/lib/libast/man/stk.3) instead of malloc to save the value; it's faster and will be auto-freed at some point. This shortens the function and makes it faster by not entering into a whole new shell context -- which also fixes another problem: the error message from put_enum() didn't cause the shell to exit for indexed enum arrays. src/cmd/ksh93/sh/name.c: nv_setlist(): - Apply a patch from David Korn that correctly sets the data type for associative arrays, fixing the ${array[@]} expansion yielding random numbers. Thanks to @JohnoKing for the pointer. https://github.com/ksh93/ksh/issues/87#issuecomment-662613887 https://www.mail-archive.com/ast-developers@lists.research.att.com/msg00697.html src/cmd/ksh93/tests/enum.sh: - Add tests checking that invalid values are correctly blocked for indexed and associative arrays of an enum type. Makes progress on: https://github.com/ksh93/ksh/issues/87
This commit is contained in:
parent
6a0e9a1a75
commit
5491fe9724
6 changed files with 30 additions and 23 deletions
10
NEWS
10
NEWS
|
@ -3,6 +3,14 @@ For full details, see the git log at: https://github.com/ksh93/ksh
|
|||
|
||||
Any uppercase BUG_* names are modernish shell bug IDs.
|
||||
|
||||
2021-02-01:
|
||||
|
||||
- Fixed: scalar arrays (-a) and associative arrays (-A) of a type created by
|
||||
'enum' allowed values not specified by the enum type, corrupting results.
|
||||
|
||||
- Fixed: the "${array[@]}" expansion for associative arrays of a type created
|
||||
by 'enum' expanded to random numbers instead of the array's values.
|
||||
|
||||
2021-01-30:
|
||||
|
||||
- The -x option to the 'command' built-in now causes it to bypass built-ins
|
||||
|
@ -12,7 +20,7 @@ Any uppercase BUG_* names are modernish shell bug IDs.
|
|||
a command with many arguments was divided into several command invocations.
|
||||
|
||||
- The 2020-08-16 fix is improved with a compile-time feature test that
|
||||
detects if and how the OS uses data alignment in the arguments list,
|
||||
detects if the OS requires extra bytes per argument in the arguments list,
|
||||
maximising the efficiency of 'command -x' for the system it runs on.
|
||||
|
||||
2021-01-24:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue