1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00

arith.c: scope(): de-obfuscate some code

This function adds the NV_ADD flag to its 'flags' variable for
nv_serach() calls subject to some checks. However, every call that
uses that variable explicitly turns off the NV_ADD bit again.

A search in the ast-open-history repo reveals that this check
briefly made a difference between versions 2010-06-25 and
2010-08-11, but it's been a complete no-op ever since.

src/cmd/ksh93/sh/arith.c: scope():
- Remove no-op code.
- Resolve the constant expressions involving the 'flags' variable,
  get rid of the variable, and just indicate the flag bitmasks
  directly in the nv_search() calls.
- Detangle and split up the excessively long 'if' construct.

No change in behaviour.

Previously noticed by Kurtis Rader for ksh2020:
https://github.com/att/ast/commit/d5ce3b05
This commit is contained in:
Martijn Dekker 2021-11-25 03:02:34 +01:00
parent 214308f81e
commit 2d65148fad

View file

@ -64,7 +64,6 @@ static Namval_t *scope(register Namval_t *np,register struct lval *lvalue,int as
register char *sub=0, *cp=(char*)np;
register Namval_t *mp;
Shell_t *shp = lvalue->shp;
int flags = HASH_NOSCOPE|HASH_SCOPE|HASH_BUCKET;
int c=0,nosub = lvalue->nosub;
Dt_t *sdict = (shp->st.real_fun? shp->st.real_fun->sdict:0);
Dt_t *nsdict = (shp->namespace?nv_dict(shp->namespace):0);
@ -100,10 +99,13 @@ static Namval_t *scope(register Namval_t *np,register struct lval *lvalue,int as
flag = 0;
cp = (char*)np;
}
else if(assign==NV_ASSIGN && nv_isnull(np) && !nv_isattr(np, ~(NV_MINIMAL|NV_NOFREE)))
flags |= NV_ADD;
if((lvalue->emode&ARITH_COMP) && dtvnext(root) && ((sdict && (mp=nv_search(cp,sdict,flags&~NV_ADD))) || (mp=nv_search(cp,root,flags&~(NV_ADD))) || (nsdict && (mp=nv_search(cp,nsdict,flags&~(NV_ADD|HASH_NOSCOPE)))) ))
np = mp;
if((lvalue->emode & ARITH_COMP) && dtvnext(root))
{
if(mp = nv_search(cp, sdict ? sdict : root, HASH_NOSCOPE|HASH_SCOPE|HASH_BUCKET))
np = mp;
else if(nsdict && (mp = nv_search(cp, nsdict, HASH_SCOPE|HASH_BUCKET)))
np = mp;
}
while(nv_isref(np))
{
#if SHOPT_FIXEDARRAY