1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-13 11:42:21 +00:00

-o posix: always recognise octals in "let" builtin

Though the "let" builtin is not itself a POSIX standard command, it
processes standard shell arithmetic, so it should recognise octals
by leading zeros as POSIX requires if the 'posix' option is on.
This overrides the setting of the 'letoctal' option.

Note that none of this applies to the ((...)) arithmetic command,
which has always recognised leading-octal zeros and does not listen
to 'letoctal'. So setting the posix mode makes this consistent.

src/cmd/ksh93/sh/arith.c:
- When running the 'let' builtin, test that both SH_LETOCTAL and
  SH_POSIX are off before stripping leading zeros to disable octal
  number recognition.
- Cosmetic: fix spurious newline.

src/cmd/ksh93/sh.1:
- Document the change.

src/cmd/ksh93/tests/shtests:
- Make sure to disable posix mode by default for regression tests.
This commit is contained in:
Martijn Dekker 2020-09-01 07:16:51 +01:00
parent 921bbcaeb7
commit b301d41731
5 changed files with 19 additions and 10 deletions

2
NEWS
View file

@ -14,6 +14,8 @@ Any uppercase BUG_* names are modernish shell bug IDs.
turned on if ksh is invoked under the name 'sh'.
For now, it:
* disables the &> redirection shorthand
* causes the 'let' arithmetic command to recognise octal numbers by
leading zeros regardless of the setting of the 'letoctal' option
2020-08-19:

View file

@ -6321,10 +6321,12 @@ to be evaluated.
.B let
only recognizes octal constants starting with
.B 0
when the
if one of the
.B set
option
options
.B letoctal
or
.B posix
is on.
See
.I "Arithmetic Evaluation"
@ -6987,6 +6989,8 @@ The
.B let
command allows octal constants starting with
.BR 0 .
If the \fBposix\fR shell option is active,
octals are recognized regardless of this option.
.TP 8
.B markdirs
All directory names resulting from file name generation have a trailing
@ -7034,6 +7038,7 @@ to fail or zero if no command has failed.
.B posix
Enable POSIX standard compatibility mode. This option
is on by default if ksh is invoked as \fBsh\fR. It
enables octal numbers in \fBlet\fR shell arithmetic (see \fBletoctal\fR), and
disables the \fB&>\fR redirection shorthand.
.TP 8
.B privileged

View file

@ -390,8 +390,11 @@ static Sfdouble_t arith(const char **ptr, struct lval *lvalue, int type, Sfdoubl
char lastbase=0, *val = xp, oerrno = errno;
lvalue->eflag = 0;
errno = 0;
if(shp->bltindata.bnode==SYSLET && !sh_isoption(SH_LETOCTAL))
{
if(shp->bltindata.bnode==SYSLET && !sh_isoption(SH_LETOCTAL) && !sh_isoption(SH_POSIX))
{ /*
* Since we're running the "let" builtin, disable octal number processing by
* skipping all initial zeros, unless the 'letoctal' or 'posix' option is on.
*/
while(*val=='0' && isdigit(val[1]))
val++;
}
@ -415,8 +418,7 @@ static Sfdouble_t arith(const char **ptr, struct lval *lvalue, int type, Sfdoubl
c='e';
else
c = *str;
if(c==GETDECIMAL(0) || c=='e' || c == 'E' || lastbase ==
16 && (c == 'p' || c == 'P'))
if(c==GETDECIMAL(0) || c=='e' || c == 'E' || lastbase == 16 && (c == 'p' || c == 'P'))
{
lvalue->isfloat=1;
r = strtold(val,&str);

View file

@ -680,9 +680,8 @@ exp='typeset -C -a x=((typeset -C -a y=( [0]=(typeset -a -l -i z=([2]=3);));))'
unset x
let x=010
[[ $x == 10 ]] || err_exit 'let treating 010 as octal'
set -o letoctal
let x=010
[[ $x == 8 ]] || err_exit 'let not treating 010 as octal with letoctal on'
(set -o letoctal; let x=010; [[ $x == 8 ]]) || err_exit 'let not treating 010 as octal with letoctal on'
(set -o posix 2>/dev/null; let x=010; [[ $x == 8 ]]) || err_exit 'let not treating 010 as octal with posix on'
float z=0
integer aa=2 a=1

View file

@ -166,7 +166,8 @@ function valxml
return $errors
}
unset DISPLAY FIGNORE HISTFILE
command set +o posix 2>/dev/null
unset DISPLAY FIGNORE HISTFILE POSIXLY_CORRECT _AST_FEATURES
export ENV=/./dev/null
trap + PIPE # unadvertized -- set SIGPIPE to SIG_DFL #