1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Fix various possible uses of uninitialised variables

Patch from OpenSUSE, slightly adapted for 93u+m. Source:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-uninitialized.dif
This commit is contained in:
Martijn Dekker 2021-01-28 04:54:41 +00:00
parent c52cb93999
commit 288b6c6517
15 changed files with 39 additions and 32 deletions

View file

@ -512,7 +512,7 @@ masterline(Sfio_t* mp, Sfio_t* lp, char* prompt, int must, int timeout, Master_t
char* t; char* t;
ssize_t n; ssize_t n;
ssize_t a; ssize_t a;
size_t promptlen; size_t promptlen = 0;
ptrdiff_t d; ptrdiff_t d;
char promptbuf[64]; char promptbuf[64];
@ -782,6 +782,8 @@ dialogue(Sfio_t* mp, Sfio_t* lp, int delay, int timeout)
!(master->buf = vmnewof(vm, 0, char, 2 * SF_BUFSIZE, 0))) !(master->buf = vmnewof(vm, 0, char, 2 * SF_BUFSIZE, 0)))
{ {
error(ERROR_SYSTEM|2, "out of space"); error(ERROR_SYSTEM|2, "out of space");
id = 0;
line = 0;
goto done; goto done;
} }
master->vm = vm; master->vm = vm;

View file

@ -1406,12 +1406,12 @@ int ed_internal(const char *src, genchar *dest)
int ed_external(const genchar *src, char *dest) int ed_external(const genchar *src, char *dest)
{ {
register genchar wc; register genchar wc;
register int c,size;
register char *dp = dest; register char *dp = dest;
char *dpmax = dp+sizeof(genchar)*MAXLINE-2; char *dpmax = dp+sizeof(genchar)*MAXLINE-2;
if((char*)src == dp) if((char*)src == dp)
{ {
char buffer[MAXLINE*sizeof(genchar)]; int c;
char buffer[MAXLINE*sizeof(genchar)] = "";
c = ed_external(src,buffer); c = ed_external(src,buffer);
#ifdef _lib_wcscpy #ifdef _lib_wcscpy
@ -1423,6 +1423,7 @@ int ed_external(const genchar *src, char *dest)
} }
while((wc = *src++) && dp<dpmax) while((wc = *src++) && dp<dpmax)
{ {
ssize_t size;
if((size = mbconv(dp, wc)) < 0) if((size = mbconv(dp, wc)) < 0)
{ {
/* copy the character as is */ /* copy the character as is */

View file

@ -1176,7 +1176,7 @@ Shell_t *sh_init(register int argc,register char *argv[], Shinit_f userinit)
static int beenhere; static int beenhere;
Shell_t *shp; Shell_t *shp;
register int n; register int n;
int type; int type = 0;
char *save_envmarker; char *save_envmarker;
static char *login_files[2]; static char *login_files[2];
memfatal(); memfatal();
@ -1846,7 +1846,7 @@ Dt_t *sh_inittree(Shell_t *shp,const struct shtable2 *name_vals)
register const struct shtable2 *tp; register const struct shtable2 *tp;
register unsigned n = 0; register unsigned n = 0;
register Dt_t *treep; register Dt_t *treep;
Dt_t *base_treep, *dict; Dt_t *base_treep, *dict = 0;
for(tp=name_vals;*tp->sh_name;tp++) for(tp=name_vals;*tp->sh_name;tp++)
n++; n++;
np = (Namval_t*)calloc(n,sizeof(Namval_t)); np = (Namval_t*)calloc(n,sizeof(Namval_t));

View file

@ -1803,7 +1803,7 @@ retry2:
int ofs_size = 0; int ofs_size = 0;
regoff_t match[2*(MATCH_MAX+1)]; regoff_t match[2*(MATCH_MAX+1)];
int nmatch, nmatch_prev, vsize_last; int nmatch, nmatch_prev, vsize_last;
char *vlast; char *vlast = NIL(char*);
while(1) while(1)
{ {
if(!v) if(!v)

View file

@ -1305,7 +1305,7 @@ Namval_t *nv_open(const char *name, Dt_t *root, int flags)
const char *msg = e_varname; const char *msg = e_varname;
char *fname = 0; char *fname = 0;
int offset = staktell(); int offset = staktell();
Dt_t *funroot; Dt_t *funroot = NIL(Dt_t*);
#if NVCACHE #if NVCACHE
struct Cache_entry *xp; struct Cache_entry *xp;
#endif #endif
@ -1779,7 +1779,7 @@ void nv_putval(register Namval_t *np, const char *string, int flags)
else else
{ {
const char *tofree=0; const char *tofree=0;
int offset,append; int offset=0,append;
#if _lib_pathnative #if _lib_pathnative
char buff[PATH_MAX]; char buff[PATH_MAX];
#endif /* _lib_pathnative */ #endif /* _lib_pathnative */

View file

@ -453,7 +453,7 @@ static Sfdouble_t lookupn(Namval_t *np, Namfun_t *handle)
char *nv_setdisc(register Namval_t* np,register const char *event,Namval_t *action,register Namfun_t *fp) char *nv_setdisc(register Namval_t* np,register const char *event,Namval_t *action,register Namfun_t *fp)
{ {
register struct vardisc *vp = (struct vardisc*)np->nvfun; register struct vardisc *vp = (struct vardisc*)np->nvfun;
register int type; register int type = -1;
char *empty = ""; char *empty = "";
while(vp) while(vp)
{ {
@ -509,6 +509,8 @@ char *nv_setdisc(register Namval_t* np,register const char *event,Namval_t *acti
} }
return(NIL(char*)); return(NIL(char*));
} }
if (type < 0)
return(NIL(char*));
/* Handle GET/SET/APPEND/UNSET disc */ /* Handle GET/SET/APPEND/UNSET disc */
if(vp && vp->fun.disc->putval!=assign) if(vp && vp->fun.disc->putval!=assign)
vp = 0; vp = 0;

View file

@ -557,7 +557,7 @@ void nv_outnode(Namval_t *np, Sfio_t* out, int indent, int special)
char *fmtq,*ep,*xp; char *fmtq,*ep,*xp;
Namval_t *mp; Namval_t *mp;
Namarr_t *ap = nv_arrayptr(np); Namarr_t *ap = nv_arrayptr(np);
int scan,tabs=0,c,more,associative = 0; int scan=0,tabs=0,c,more,associative = 0;
int saveI = Indent; int saveI = Indent;
Indent = indent; Indent = indent;
if(ap) if(ap)
@ -670,7 +670,7 @@ void nv_outnode(Namval_t *np, Sfio_t* out, int indent, int special)
static void outval(char *name, const char *vname, struct Walk *wp) static void outval(char *name, const char *vname, struct Walk *wp)
{ {
register Namval_t *np, *nq, *last_table=wp->shp->last_table; register Namval_t *np, *nq=0, *last_table=wp->shp->last_table;
register Namfun_t *fp; register Namfun_t *fp;
int isarray=0, special=0,mode=0; int isarray=0, special=0,mode=0;
if(*name!='.' || vname[strlen(vname)-1]==']') if(*name!='.' || vname[strlen(vname)-1]==']')

View file

@ -826,9 +826,10 @@ void nv_newtype(Namval_t *mp)
Namval_t *nv_mktype(Namval_t **nodes, int numnodes) Namval_t *nv_mktype(Namval_t **nodes, int numnodes)
{ {
Namval_t *mp=nodes[0], *bp=0, *np, *nq, **mnodes=nodes; Namval_t *mp=nodes[0], *bp=0, *np, *nq, **mnodes=nodes;
int i,j,k,m,n,nd=0,nref=0,iref=0,inherit=0; int i,j,k,nd=0,nref=0,iref=0,inherit=0;
int size=sizeof(NV_DATA), dsize=0, nnodes; int size=sizeof(NV_DATA), dsize=0, nnodes;
size_t offset=0; size_t offset=0,m;
ssize_t n;
char *name=0, *cp, *sp, **help; char *name=0, *cp, *sp, **help;
Namtype_t *pp,*qp=0,*dp,*tp; Namtype_t *pp,*qp=0,*dp,*tp;
Dt_t *root = nv_dict(mp); Dt_t *root = nv_dict(mp);
@ -841,6 +842,7 @@ Namval_t *nv_mktype(Namval_t **nodes, int numnodes)
_nv_unset(nodes[0],NV_RDONLY); _nv_unset(nodes[0],NV_RDONLY);
errormsg(SH_DICT,ERROR_exit(1),e_badtypedef,cp); errormsg(SH_DICT,ERROR_exit(1),e_badtypedef,cp);
} }
n=strlen(nodes[1]->nvname);
for(nnodes=1,i=1; i <numnodes; i++) for(nnodes=1,i=1; i <numnodes; i++)
{ {
np=nodes[i]; np=nodes[i];

View file

@ -302,7 +302,7 @@ static Shnode_t *getanode(Lex_t *lp, struct argnod *ap)
*/ */
static Shnode_t *makelist(Lex_t *lexp, int type, Shnode_t *l, Shnode_t *r) static Shnode_t *makelist(Lex_t *lexp, int type, Shnode_t *l, Shnode_t *r)
{ {
register Shnode_t *t; register Shnode_t *t = NIL(Shnode_t*);
if(!l || !r) if(!l || !r)
sh_syntax(lexp); sh_syntax(lexp);
else else
@ -808,7 +808,7 @@ static Shnode_t *funct(Lex_t *lexp)
{ {
struct comnod *ac; struct comnod *ac;
char *cp, **argv, **argv0; char *cp, **argv, **argv0;
int c; int c=-1;
t->funct.functargs = ac = (struct comnod*)simple(lexp,SH_NOIO|SH_FUNDEF,NIL(struct ionod*)); t->funct.functargs = ac = (struct comnod*)simple(lexp,SH_NOIO|SH_FUNDEF,NIL(struct ionod*));
if(ac->comset || (ac->comtyp&COMSCAN)) if(ac->comset || (ac->comtyp&COMSCAN))
errormsg(SH_DICT,ERROR_exit(3),e_lexsyntax4,lexp->sh->inlineno); errormsg(SH_DICT,ERROR_exit(3),e_lexsyntax4,lexp->sh->inlineno);

View file

@ -1426,7 +1426,7 @@ int sh_exec(register const Shnode_t *t, int flags)
Namval_t node; Namval_t node;
#endif /* SHOPT_NAMESPACE */ #endif /* SHOPT_NAMESPACE */
struct Namref nr; struct Namref nr;
long mode; long mode = 0;
register struct slnod *slp; register struct slnod *slp;
if(!np->nvalue.ip) if(!np->nvalue.ip)
{ {
@ -1771,8 +1771,8 @@ int sh_exec(register const Shnode_t *t, int flags)
* don't create a new process, just * don't create a new process, just
* save and restore io-streams * save and restore io-streams
*/ */
pid_t pid; pid_t pid = 0;
int jmpval, waitall; int jmpval, waitall = 0;
int simple = (t->fork.forktre->tre.tretyp&COMMSK)==TCOM; int simple = (t->fork.forktre->tre.tretyp&COMMSK)==TCOM;
struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt));
if(shp->subshell) if(shp->subshell)
@ -2162,7 +2162,7 @@ int sh_exec(register const Shnode_t *t, int flags)
Shnode_t *tt = t->wh.whtre; Shnode_t *tt = t->wh.whtre;
#if SHOPT_FILESCAN #if SHOPT_FILESCAN
Sfio_t *iop=0; Sfio_t *iop=0;
int savein; int savein=-1;
#endif /*SHOPT_FILESCAN*/ #endif /*SHOPT_FILESCAN*/
#if SHOPT_OPTIMIZE #if SHOPT_OPTIMIZE
int jmpval = ((struct checkpt*)shp->jmplist)->mode; int jmpval = ((struct checkpt*)shp->jmplist)->mode;
@ -2579,7 +2579,7 @@ int sh_exec(register const Shnode_t *t, int flags)
else else
{ {
register int traceon=0; register int traceon=0;
register char *right; register char *right = 0;
register char *trap; register char *trap;
char *argv[6]; char *argv[6];
n = type>>TSHIFT; n = type>>TSHIFT;
@ -2613,7 +2613,7 @@ int sh_exec(register const Shnode_t *t, int flags)
} }
else if(type&TBINARY) else if(type&TBINARY)
{ {
char *op; char *op = 0;
int pattern = 0; int pattern = 0;
if(trap || traceon) if(trap || traceon)
op = (char*)(shtab_testops+(n&037)-1)->sh_name; op = (char*)(shtab_testops+(n&037)-1)->sh_name;
@ -3277,11 +3277,11 @@ static void sh_funct(Shell_t *shp,Namval_t *np,int argn, char *argv[],struct arg
int sh_fun(Namval_t *np, Namval_t *nq, char *argv[]) int sh_fun(Namval_t *np, Namval_t *nq, char *argv[])
{ {
Shell_t *shp = sh_getinterp(); Shell_t *shp = sh_getinterp();
register int offset; register int offset = 0;
register char *base; register char *base;
Namval_t node; Namval_t node;
struct Namref nr; struct Namref nr;
long mode; long mode = 0;
char *prefix = shp->prefix; char *prefix = shp->prefix;
int n=0; int n=0;
char *av[3]; char *av[3];

View file

@ -211,8 +211,8 @@ S2F_function(str, end) char* str; char** end;
int decimal = 0; int decimal = 0;
int thousand = 0; int thousand = 0;
int part = 0; int part = 0;
int back_part; int back_part = 0;
S2F_batch back_n; S2F_batch back_n = 0;
S2F_number v; S2F_number v;
S2F_number p; S2F_number p;
S2F_part_t parts[16]; S2F_part_t parts[16];

View file

@ -53,7 +53,7 @@ int type; /* >0: scanf, =0: printf, -1: internal */
#endif #endif
{ {
int base, fmt, flags, dot, width, precis; int base, fmt, flags, dot, width, precis;
ssize_t n_str, size; ssize_t n_str, size = 0;
char *t_str, *sp; char *t_str, *sp;
int v, n, skip, dollar, decimal, thousand; int v, n, skip, dollar, decimal, thousand;
Sffmt_t savft; Sffmt_t savft;

View file

@ -101,7 +101,7 @@ char* form; /* format to use */
va_list args; /* arg list if !argf */ va_list args; /* arg list if !argf */
#endif #endif
{ {
int n, v, w, k, n_s, base, fmt, flags; int n, v=0, w, k, n_s, base, fmt, flags;
Sflong_t lv; Sflong_t lv;
char *sp, *ssp, *endsp, *ep, *endep; char *sp, *ssp, *endsp, *ep, *endep;
int dot, width, precis, sign, decpt; int dot, width, precis, sign, decpt;
@ -129,7 +129,7 @@ va_list args; /* arg list if !argf */
int decimal = 0, thousand = 0; int decimal = 0, thousand = 0;
#if _has_multibyte #if _has_multibyte
wchar_t* wsp; wchar_t* wsp = 0;
SFMBDCL(fmbs) /* state of format string */ SFMBDCL(fmbs) /* state of format string */
SFMBDCL(mbs) /* state of some string */ SFMBDCL(mbs) /* state of some string */
#ifdef mbwidth #ifdef mbwidth

View file

@ -60,13 +60,13 @@ stropt(const char* as, const void* tab, int siz, int(*f)(void*, const void*, int
register char* v; register char* v;
register char* t; register char* t;
char** p; char** p;
char* u; char* u = 0;
char* x; char* x;
char* e; char* e;
int n; int n;
int ql; int ql;
int qr; int qr;
int qc; int qc = 0;
if (!as) n = 0; if (!as) n = 0;
else if (!(x = s = strdup(as))) n = -1; else if (!(x = s = strdup(as))) n = -1;

View file

@ -230,13 +230,13 @@ S2I_function(a, e, base) const char* a; char** e; int base;
#endif #endif
register S2I_unumber n; register S2I_unumber n;
register S2I_unumber x; register S2I_unumber x;
register int c; register int c = 0;
register int shift; register int shift;
register unsigned char* p; register unsigned char* p;
register unsigned char* cv; register unsigned char* cv;
unsigned char* b; unsigned char* b;
unsigned char* k; unsigned char* k;
S2I_unumber v; S2I_unumber v = 0;
#if S2I_multiplier #if S2I_multiplier
register int base; register int base;
#endif #endif