1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00
cde/src/cmd/ksh93/sh
Martijn Dekker a66cd72f7d arith: implement range checking for enum types
Within arithmetic expressions, enumeration values of variables of a
type created with the 'enum' command translate to index numbers
from 0 to the number of elements minus 1. However, there was no
range checking on this in the arithmetic subsystem, allowing the
assignment of out-of-range values that did not correspond to any
enumeration value.

Variables of an enum type are internally unsigned short integers
(NV_UINT16), like those created with 'integer -su', except with an
additional discipline function (ENUM_disc).

src/cmd/ksh93/bltins/enum.c,
src/cmd/ksh93/include/builtins.h:
- To implement range checking, the arithmetic system needs access
  to the 'nelem' (number of elements) member of 'struct Enum'. This
  is only defined locally in enum.c. We could move that to name.h
  so arith.c can access it, but enum.c has code that supports
  compiling as standalone. So, instead, define a quick extern
  function, b_enum_elem(), that does the necessary type conversion
  and returns a type's number of elements.
- Add --man documentation for the arithmetic subsystem behaviour
  for enum types. Tell the enuminfo() function, which dynamically
  inserts values into the documentation, how to process new \f tags
  'lastv' (the last-defined value) and 'lastn' (the number of the
  last element).

src/cmd/ksh93/sh/arith.c: arith():
- For NV_UINT16 variables with an ENUM_disc discipline, check the
  range using b_enum_elem() and error out if necessary.

Resolves: https://github.com/ksh93/ksh/issues/335
2021-11-23 22:10:40 +01:00
..
args.c arithmetic: Fix the octal leading zero mess (#337) 2021-11-17 04:28:08 +01:00
arith.c arith: implement range checking for enum types 2021-11-23 22:10:40 +01:00
array.c nv_associative(): clarify value indicating enum (re: 6b9703ff) 2021-11-21 17:43:14 +01:00
defs.c Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
deparse.c Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
expand.c Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
fault.c test/[: Improve error status > 1 (re: 7003aba4, cd2cf236, ef1f53b5) 2021-11-22 15:37:04 +01:00
fcin.c Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
init.c Fix a few issues with $RANDOM seeding in subshells (#339) 2021-11-19 08:18:44 +01:00
io.c Fix backtick comsubs by making them act like $(modern) ones 2021-08-13 09:14:11 +02:00
jobs.c Comments: document job control flags (re: 41ebb55a) 2021-11-05 03:21:44 +00:00
lex.c test/[: binary operators: fix '<' and add '=~'; some more cleanups 2021-11-14 02:46:34 +01:00
macro.c arithmetic: Fix the octal leading zero mess (#337) 2021-11-17 04:28:08 +01:00
main.c Fix bug on closed stdout; improve BUG_PUTIOERR fix (re: 93e15a30) 2021-11-07 15:44:06 +00:00
name.c arithmetic: Fix the octal leading zero mess (#337) 2021-11-17 04:28:08 +01:00
nvdisc.c arithmetic: Fix the octal leading zero mess (#337) 2021-11-17 04:28:08 +01:00
nvtree.c Fix more bugs that occur when enabling ASan (#293) 2021-05-02 04:06:30 +01:00
nvtype.c typeset -T shouldn't list types created with enum (#340) 2021-11-20 09:48:48 +01:00
parse.c Fix enum type definition pre-parsing for shcomp and dot/source 2021-11-21 17:43:55 +01:00
path.c Fix two more 'command' bugs 2021-05-05 02:43:18 +01:00
pmain.c Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
shcomp.c shcomp: refuse to write binary data to terminal 2021-11-16 23:34:52 +01:00
streval.c test/[: Improve error status > 1 (re: 7003aba4, cd2cf236, ef1f53b5) 2021-11-22 15:37:04 +01:00
string.c Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
subshell.c Fix a few issues with $RANDOM seeding in subshells (#339) 2021-11-19 08:18:44 +01:00
suid_exec.c Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
tdump.c Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
timers.c Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
trestore.c Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
waitevent.c Add ksh 93u+m contributors notice to 964 copyright headers 2021-04-26 00:19:31 +01:00
xec.c xtrace: fix restore of standard error stream state 2021-11-07 22:41:55 +00:00