Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readonly attribute size fix #201

Merged
merged 1 commit into from
Mar 3, 2021
Merged

Conversation

hyenias
Copy link

@hyenias hyenias commented Mar 2, 2021

Corrected the size of attribute(s) being overwritten with 0 when
'readonly' or 'typeset -r' was applied to an existing variable. Since
one cannot set any attributes with the 'readonly' command, its function
call to setall() needs to be adjusted to acquire the current size from
the old size or existing size of the variable. A plain 'typeset -r' is
the same as 'readonly' in that it needs to load the old size as its
current size for use in the subsequent to call to nv_newattr().

src/cmd/ksh93/bltins/typeset.c: setall():

  • Both 'readonly' and 'typeset -r' end up calling setall(). setall()
    has full visibility into all user supplied values and existing
    values that are needed to differentiate whereas name.c newattr()
    acquires combined state flags.
  • Added a conditional check if the readonly flag was requested by
    user then meets the criteria of having present size of 0, cannot
    be a numeric nor binary string, and is void of presence of any of
    the justified string attributes.
  • -L/R/Z justified string attributes if not given a value default
    to a size of 0 which means to autosize. A binary string can have
    a fixed field size, e.g. -bZ. The present of any of the -L/R/Z
    attribules means that current size is valid and should be used
    even if it is zero.

src/cmd/ksh93/tests/attributes.sh:

  • Added various tests to capture and reiterate that 'readonly' should
    be equivalent to 'typeset -r' and applying them should not alter the
    previous existing size unless additional attributes are set along
    with typeset command.

Corrected the size of attribute(s) being overwritten with 0 when
'readonly' or 'typeset -r' was applied to an existing variable. Since
one cannot set any attributes with the 'readonly' command, its function
call to setall() needs to be adjusted to acquire the current size from
the old size or existing size of the variable. A plain 'typeset -r' is
the same as 'readonly' in that it needs to load the old size as its
current size for use in the subsequent to call to nv_newattr().

src/cmd/ksh93/bltins/typeset.c: setall():
- Both 'readonly' and 'typeset -r' end up calling setall(). setall()
  has full visibility into all user supplied values and existing
  values that are needed to differentiate whereas name.c newattr()
  acquires combined state flags.
- Added a conditional check if the readonly flag was requested by
  user then meets the criteria of having present size of 0, cannot
  be a numeric nor binary string, and is void of presence of any of
  the justified string attributes.
- -L/R/Z justified string attributes if not given a value default
  to a size of 0 which means to autosize. A binary string can have
  a fixed field size, e.g. -bZ. The present of any of the -L/R/Z
  attribules means that current size is valid and should be used
  even if it is zero.

src/cmd/ksh93/tests/attributes.sh:
- Added various tests to capture and reiterate that 'readonly' should
  be equivalent to 'typeset -r' and applying them should not alter the
  previous existing size unless additional attributes are set along
  with typeset command.
@McDutchie
Copy link

LGTM, thanks!

@McDutchie McDutchie merged commit a61430f into ksh93:master Mar 3, 2021
@hyenias hyenias deleted the readonly-size branch January 29, 2022 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants