diff --git a/NEWS b/NEWS index 3d8720350..ce7b9e0d3 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,10 @@ For full details, see the git log at: https://github.com/ksh93/ksh Any uppercase BUG_* names are modernish shell bug IDs. +2021-01-07: + +- Fixed a crash that could occur while ksh updated ${.sh.match}. + 2021-01-05: - Fixed a bug in 'cd' that caused 'cd ./foo' to search for 'foo' in $CDPATH. diff --git a/src/cmd/ksh93/include/version.h b/src/cmd/ksh93/include/version.h index c8c295671..a147e2d1f 100644 --- a/src/cmd/ksh93/include/version.h +++ b/src/cmd/ksh93/include/version.h @@ -20,7 +20,7 @@ #define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */ #define SH_RELEASE_SVER "1.0.0-alpha" /* semantic version number: https://semver.org */ -#define SH_RELEASE_DATE "2021-01-05" /* must be in this format for $((.sh.version)) */ +#define SH_RELEASE_DATE "2021-01-07" /* must be in this format for $((.sh.version)) */ /* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */ /* Arithmetic $((.sh.version)) uses the last 10 chars, so the date must be at the end. */ diff --git a/src/cmd/ksh93/sh/init.c b/src/cmd/ksh93/sh/init.c index 51fc5cdeb..ee0cef4f9 100644 --- a/src/cmd/ksh93/sh/init.c +++ b/src/cmd/ksh93/sh/init.c @@ -725,6 +725,7 @@ void sh_setmatch(Shell_t *shp,const char *v, int vsize, int nmatch, regoff_t mat register int i,n,x; unsigned int savesub = shp->subshell; Namarr_t *ap = nv_arrayptr(SH_MATCHNOD); + Namarr_t *ap_save = ap; shp->subshell = 0; #ifndef SHOPT_2DMATCH index = 0; @@ -754,8 +755,7 @@ void sh_setmatch(Shell_t *shp,const char *v, int vsize, int nmatch, regoff_t mat nv_disc(SH_MATCHNOD,&mp->hdr,NV_LAST); if(nmatch) nv_putsub(SH_MATCHNOD, NIL(char*), (nmatch-1)|ARRAY_FILL|ARRAY_SETSUB); - ap = nv_arrayptr(SH_MATCHNOD); - ap->nelem = mp->nmatch = nmatch; + ap_save->nelem = mp->nmatch = nmatch; mp->v = v; mp->first = match[0]; } @@ -773,8 +773,7 @@ void sh_setmatch(Shell_t *shp,const char *v, int vsize, int nmatch, regoff_t mat nv_putsub(SH_MATCHNOD, (char*)0, i); nv_arraychild(SH_MATCHNOD, np,0); } - if(ap = nv_arrayptr(SH_MATCHNOD)) - ap->nelem = mp->nmatch; + ap_save->nelem = mp->nmatch; } ap = nv_arrayptr(np); nv_putsub(np, NIL(char*), index|ARRAY_FILL|ARRAY_SETSUB); @@ -808,7 +807,7 @@ void sh_setmatch(Shell_t *shp,const char *v, int vsize, int nmatch, regoff_t mat x=1; } - ap->nelem -= x; + ap_save->nelem -= x; while(i < 2*mp->nmatch) mp->match[index+i++] = -1; memcpy(mp->val,v+n,vsize);