Skip to content

Commit

Permalink
Fix various possible uses of uninitialised variables
Browse files Browse the repository at this point in the history
Patch from OpenSUSE, slightly adapted for 93u+m. Source:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-uninitialized.dif
  • Loading branch information
McDutchie committed Jan 28, 2021
1 parent c52cb93 commit 288b6c6
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 32 deletions.
4 changes: 3 additions & 1 deletion src/cmd/builtin/pty.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ masterline(Sfio_t* mp, Sfio_t* lp, char* prompt, int must, int timeout, Master_t
char* t;
ssize_t n;
ssize_t a;
size_t promptlen;
size_t promptlen = 0;
ptrdiff_t d;
char promptbuf[64];

Expand Down Expand Up @@ -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)))
{
error(ERROR_SYSTEM|2, "out of space");
id = 0;
line = 0;
goto done;
}
master->vm = vm;
Expand Down
5 changes: 3 additions & 2 deletions src/cmd/ksh93/edit/edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1406,12 +1406,12 @@ int ed_internal(const char *src, genchar *dest)
int ed_external(const genchar *src, char *dest)
{
register genchar wc;
register int c,size;
register char *dp = dest;
char *dpmax = dp+sizeof(genchar)*MAXLINE-2;
if((char*)src == dp)
{
char buffer[MAXLINE*sizeof(genchar)];
int c;
char buffer[MAXLINE*sizeof(genchar)] = "";
c = ed_external(src,buffer);

#ifdef _lib_wcscpy
Expand All @@ -1423,6 +1423,7 @@ int ed_external(const genchar *src, char *dest)
}
while((wc = *src++) && dp<dpmax)
{
ssize_t size;
if((size = mbconv(dp, wc)) < 0)
{
/* copy the character as is */
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/ksh93/sh/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ Shell_t *sh_init(register int argc,register char *argv[], Shinit_f userinit)
static int beenhere;
Shell_t *shp;
register int n;
int type;
int type = 0;
char *save_envmarker;
static char *login_files[2];
memfatal();
Expand Down Expand Up @@ -1846,7 +1846,7 @@ Dt_t *sh_inittree(Shell_t *shp,const struct shtable2 *name_vals)
register const struct shtable2 *tp;
register unsigned n = 0;
register Dt_t *treep;
Dt_t *base_treep, *dict;
Dt_t *base_treep, *dict = 0;
for(tp=name_vals;*tp->sh_name;tp++)
n++;
np = (Namval_t*)calloc(n,sizeof(Namval_t));
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/sh/macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -1803,7 +1803,7 @@ static int varsub(Mac_t *mp)
int ofs_size = 0;
regoff_t match[2*(MATCH_MAX+1)];
int nmatch, nmatch_prev, vsize_last;
char *vlast;
char *vlast = NIL(char*);
while(1)
{
if(!v)
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/ksh93/sh/name.c
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ Namval_t *nv_open(const char *name, Dt_t *root, int flags)
const char *msg = e_varname;
char *fname = 0;
int offset = staktell();
Dt_t *funroot;
Dt_t *funroot = NIL(Dt_t*);
#if NVCACHE
struct Cache_entry *xp;
#endif
Expand Down Expand Up @@ -1779,7 +1779,7 @@ void nv_putval(register Namval_t *np, const char *string, int flags)
else
{
const char *tofree=0;
int offset,append;
int offset=0,append;
#if _lib_pathnative
char buff[PATH_MAX];
#endif /* _lib_pathnative */
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/ksh93/sh/nvdisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
register struct vardisc *vp = (struct vardisc*)np->nvfun;
register int type;
register int type = -1;
char *empty = "";
while(vp)
{
Expand Down Expand Up @@ -509,6 +509,8 @@ char *nv_setdisc(register Namval_t* np,register const char *event,Namval_t *acti
}
return(NIL(char*));
}
if (type < 0)
return(NIL(char*));
/* Handle GET/SET/APPEND/UNSET disc */
if(vp && vp->fun.disc->putval!=assign)
vp = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/ksh93/sh/nvtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ void nv_outnode(Namval_t *np, Sfio_t* out, int indent, int special)
char *fmtq,*ep,*xp;
Namval_t *mp;
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;
Indent = indent;
if(ap)
Expand Down Expand Up @@ -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)
{
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;
int isarray=0, special=0,mode=0;
if(*name!='.' || vname[strlen(vname)-1]==']')
Expand Down
6 changes: 4 additions & 2 deletions src/cmd/ksh93/sh/nvtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,9 +826,10 @@ void nv_newtype(Namval_t *mp)
Namval_t *nv_mktype(Namval_t **nodes, int numnodes)
{
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;
size_t offset=0;
size_t offset=0,m;
ssize_t n;
char *name=0, *cp, *sp, **help;
Namtype_t *pp,*qp=0,*dp,*tp;
Dt_t *root = nv_dict(mp);
Expand All @@ -841,6 +842,7 @@ Namval_t *nv_mktype(Namval_t **nodes, int numnodes)
_nv_unset(nodes[0],NV_RDONLY);
errormsg(SH_DICT,ERROR_exit(1),e_badtypedef,cp);
}
n=strlen(nodes[1]->nvname);
for(nnodes=1,i=1; i <numnodes; i++)
{
np=nodes[i];
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/ksh93/sh/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
register Shnode_t *t;
register Shnode_t *t = NIL(Shnode_t*);
if(!l || !r)
sh_syntax(lexp);
else
Expand Down Expand Up @@ -808,7 +808,7 @@ static Shnode_t *funct(Lex_t *lexp)
{
struct comnod *ac;
char *cp, **argv, **argv0;
int c;
int c=-1;
t->funct.functargs = ac = (struct comnod*)simple(lexp,SH_NOIO|SH_FUNDEF,NIL(struct ionod*));
if(ac->comset || (ac->comtyp&COMSCAN))
errormsg(SH_DICT,ERROR_exit(3),e_lexsyntax4,lexp->sh->inlineno);
Expand Down
16 changes: 8 additions & 8 deletions src/cmd/ksh93/sh/xec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ int sh_exec(register const Shnode_t *t, int flags)
Namval_t node;
#endif /* SHOPT_NAMESPACE */
struct Namref nr;
long mode;
long mode = 0;
register struct slnod *slp;
if(!np->nvalue.ip)
{
Expand Down Expand Up @@ -1771,8 +1771,8 @@ int sh_exec(register const Shnode_t *t, int flags)
* don't create a new process, just
* save and restore io-streams
*/
pid_t pid;
int jmpval, waitall;
pid_t pid = 0;
int jmpval, waitall = 0;
int simple = (t->fork.forktre->tre.tretyp&COMMSK)==TCOM;
struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt));
if(shp->subshell)
Expand Down Expand Up @@ -2162,7 +2162,7 @@ int sh_exec(register const Shnode_t *t, int flags)
Shnode_t *tt = t->wh.whtre;
#if SHOPT_FILESCAN
Sfio_t *iop=0;
int savein;
int savein=-1;
#endif /*SHOPT_FILESCAN*/
#if SHOPT_OPTIMIZE
int jmpval = ((struct checkpt*)shp->jmplist)->mode;
Expand Down Expand Up @@ -2579,7 +2579,7 @@ int sh_exec(register const Shnode_t *t, int flags)
else
{
register int traceon=0;
register char *right;
register char *right = 0;
register char *trap;
char *argv[6];
n = type>>TSHIFT;
Expand Down Expand Up @@ -2613,7 +2613,7 @@ int sh_exec(register const Shnode_t *t, int flags)
}
else if(type&TBINARY)
{
char *op;
char *op = 0;
int pattern = 0;
if(trap || traceon)
op = (char*)(shtab_testops+(n&037)-1)->sh_name;
Expand Down Expand Up @@ -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[])
{
Shell_t *shp = sh_getinterp();
register int offset;
register int offset = 0;
register char *base;
Namval_t node;
struct Namref nr;
long mode;
long mode = 0;
char *prefix = shp->prefix;
int n=0;
char *av[3];
Expand Down
4 changes: 2 additions & 2 deletions src/lib/libast/sfio/sfstrtof.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ S2F_function(str, end) char* str; char** end;
int decimal = 0;
int thousand = 0;
int part = 0;
int back_part;
S2F_batch back_n;
int back_part = 0;
S2F_batch back_n = 0;
S2F_number v;
S2F_number p;
S2F_part_t parts[16];
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libast/sfio/sftable.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int type; /* >0: scanf, =0: printf, -1: internal */
#endif
{
int base, fmt, flags, dot, width, precis;
ssize_t n_str, size;
ssize_t n_str, size = 0;
char *t_str, *sp;
int v, n, skip, dollar, decimal, thousand;
Sffmt_t savft;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/libast/sfio/sfvprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ char* form; /* format to use */
va_list args; /* arg list if !argf */
#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;
char *sp, *ssp, *endsp, *ep, *endep;
int dot, width, precis, sign, decpt;
Expand Down Expand Up @@ -129,7 +129,7 @@ va_list args; /* arg list if !argf */
int decimal = 0, thousand = 0;

#if _has_multibyte
wchar_t* wsp;
wchar_t* wsp = 0;
SFMBDCL(fmbs) /* state of format string */
SFMBDCL(mbs) /* state of some string */
#ifdef mbwidth
Expand Down
4 changes: 2 additions & 2 deletions src/lib/libast/string/stropt.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ stropt(const char* as, const void* tab, int siz, int(*f)(void*, const void*, int
register char* v;
register char* t;
char** p;
char* u;
char* u = 0;
char* x;
char* e;
int n;
int ql;
int qr;
int qc;
int qc = 0;

if (!as) n = 0;
else if (!(x = s = strdup(as))) n = -1;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/libast/string/strtoi.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,13 @@ S2I_function(a, e, base) const char* a; char** e; int base;
#endif
register S2I_unumber n;
register S2I_unumber x;
register int c;
register int c = 0;
register int shift;
register unsigned char* p;
register unsigned char* cv;
unsigned char* b;
unsigned char* k;
S2I_unumber v;
S2I_unumber v = 0;
#if S2I_multiplier
register int base;
#endif
Expand Down

0 comments on commit 288b6c6

Please sign in to comment.