Skip to content

Commit 288b6c6

Browse files
committed
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
1 parent c52cb93 commit 288b6c6

File tree

15 files changed

+39
-32
lines changed

15 files changed

+39
-32
lines changed

src/cmd/builtin/pty.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ masterline(Sfio_t* mp, Sfio_t* lp, char* prompt, int must, int timeout, Master_t
512512
char* t;
513513
ssize_t n;
514514
ssize_t a;
515-
size_t promptlen;
515+
size_t promptlen = 0;
516516
ptrdiff_t d;
517517
char promptbuf[64];
518518

@@ -782,6 +782,8 @@ dialogue(Sfio_t* mp, Sfio_t* lp, int delay, int timeout)
782782
!(master->buf = vmnewof(vm, 0, char, 2 * SF_BUFSIZE, 0)))
783783
{
784784
error(ERROR_SYSTEM|2, "out of space");
785+
id = 0;
786+
line = 0;
785787
goto done;
786788
}
787789
master->vm = vm;

src/cmd/ksh93/edit/edit.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,12 +1406,12 @@ int ed_internal(const char *src, genchar *dest)
14061406
int ed_external(const genchar *src, char *dest)
14071407
{
14081408
register genchar wc;
1409-
register int c,size;
14101409
register char *dp = dest;
14111410
char *dpmax = dp+sizeof(genchar)*MAXLINE-2;
14121411
if((char*)src == dp)
14131412
{
1414-
char buffer[MAXLINE*sizeof(genchar)];
1413+
int c;
1414+
char buffer[MAXLINE*sizeof(genchar)] = "";
14151415
c = ed_external(src,buffer);
14161416

14171417
#ifdef _lib_wcscpy
@@ -1423,6 +1423,7 @@ int ed_external(const genchar *src, char *dest)
14231423
}
14241424
while((wc = *src++) && dp<dpmax)
14251425
{
1426+
ssize_t size;
14261427
if((size = mbconv(dp, wc)) < 0)
14271428
{
14281429
/* copy the character as is */

src/cmd/ksh93/sh/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ Shell_t *sh_init(register int argc,register char *argv[], Shinit_f userinit)
11761176
static int beenhere;
11771177
Shell_t *shp;
11781178
register int n;
1179-
int type;
1179+
int type = 0;
11801180
char *save_envmarker;
11811181
static char *login_files[2];
11821182
memfatal();
@@ -1846,7 +1846,7 @@ Dt_t *sh_inittree(Shell_t *shp,const struct shtable2 *name_vals)
18461846
register const struct shtable2 *tp;
18471847
register unsigned n = 0;
18481848
register Dt_t *treep;
1849-
Dt_t *base_treep, *dict;
1849+
Dt_t *base_treep, *dict = 0;
18501850
for(tp=name_vals;*tp->sh_name;tp++)
18511851
n++;
18521852
np = (Namval_t*)calloc(n,sizeof(Namval_t));

src/cmd/ksh93/sh/macro.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,7 @@ static int varsub(Mac_t *mp)
18031803
int ofs_size = 0;
18041804
regoff_t match[2*(MATCH_MAX+1)];
18051805
int nmatch, nmatch_prev, vsize_last;
1806-
char *vlast;
1806+
char *vlast = NIL(char*);
18071807
while(1)
18081808
{
18091809
if(!v)

src/cmd/ksh93/sh/name.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ Namval_t *nv_open(const char *name, Dt_t *root, int flags)
13051305
const char *msg = e_varname;
13061306
char *fname = 0;
13071307
int offset = staktell();
1308-
Dt_t *funroot;
1308+
Dt_t *funroot = NIL(Dt_t*);
13091309
#if NVCACHE
13101310
struct Cache_entry *xp;
13111311
#endif
@@ -1779,7 +1779,7 @@ void nv_putval(register Namval_t *np, const char *string, int flags)
17791779
else
17801780
{
17811781
const char *tofree=0;
1782-
int offset,append;
1782+
int offset=0,append;
17831783
#if _lib_pathnative
17841784
char buff[PATH_MAX];
17851785
#endif /* _lib_pathnative */

src/cmd/ksh93/sh/nvdisc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ static Sfdouble_t lookupn(Namval_t *np, Namfun_t *handle)
453453
char *nv_setdisc(register Namval_t* np,register const char *event,Namval_t *action,register Namfun_t *fp)
454454
{
455455
register struct vardisc *vp = (struct vardisc*)np->nvfun;
456-
register int type;
456+
register int type = -1;
457457
char *empty = "";
458458
while(vp)
459459
{
@@ -509,6 +509,8 @@ char *nv_setdisc(register Namval_t* np,register const char *event,Namval_t *acti
509509
}
510510
return(NIL(char*));
511511
}
512+
if (type < 0)
513+
return(NIL(char*));
512514
/* Handle GET/SET/APPEND/UNSET disc */
513515
if(vp && vp->fun.disc->putval!=assign)
514516
vp = 0;

src/cmd/ksh93/sh/nvtree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ void nv_outnode(Namval_t *np, Sfio_t* out, int indent, int special)
557557
char *fmtq,*ep,*xp;
558558
Namval_t *mp;
559559
Namarr_t *ap = nv_arrayptr(np);
560-
int scan,tabs=0,c,more,associative = 0;
560+
int scan=0,tabs=0,c,more,associative = 0;
561561
int saveI = Indent;
562562
Indent = indent;
563563
if(ap)
@@ -670,7 +670,7 @@ void nv_outnode(Namval_t *np, Sfio_t* out, int indent, int special)
670670

671671
static void outval(char *name, const char *vname, struct Walk *wp)
672672
{
673-
register Namval_t *np, *nq, *last_table=wp->shp->last_table;
673+
register Namval_t *np, *nq=0, *last_table=wp->shp->last_table;
674674
register Namfun_t *fp;
675675
int isarray=0, special=0,mode=0;
676676
if(*name!='.' || vname[strlen(vname)-1]==']')

src/cmd/ksh93/sh/nvtype.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,9 +826,10 @@ void nv_newtype(Namval_t *mp)
826826
Namval_t *nv_mktype(Namval_t **nodes, int numnodes)
827827
{
828828
Namval_t *mp=nodes[0], *bp=0, *np, *nq, **mnodes=nodes;
829-
int i,j,k,m,n,nd=0,nref=0,iref=0,inherit=0;
829+
int i,j,k,nd=0,nref=0,iref=0,inherit=0;
830830
int size=sizeof(NV_DATA), dsize=0, nnodes;
831-
size_t offset=0;
831+
size_t offset=0,m;
832+
ssize_t n;
832833
char *name=0, *cp, *sp, **help;
833834
Namtype_t *pp,*qp=0,*dp,*tp;
834835
Dt_t *root = nv_dict(mp);
@@ -841,6 +842,7 @@ Namval_t *nv_mktype(Namval_t **nodes, int numnodes)
841842
_nv_unset(nodes[0],NV_RDONLY);
842843
errormsg(SH_DICT,ERROR_exit(1),e_badtypedef,cp);
843844
}
845+
n=strlen(nodes[1]->nvname);
844846
for(nnodes=1,i=1; i <numnodes; i++)
845847
{
846848
np=nodes[i];

src/cmd/ksh93/sh/parse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ static Shnode_t *getanode(Lex_t *lp, struct argnod *ap)
302302
*/
303303
static Shnode_t *makelist(Lex_t *lexp, int type, Shnode_t *l, Shnode_t *r)
304304
{
305-
register Shnode_t *t;
305+
register Shnode_t *t = NIL(Shnode_t*);
306306
if(!l || !r)
307307
sh_syntax(lexp);
308308
else
@@ -808,7 +808,7 @@ static Shnode_t *funct(Lex_t *lexp)
808808
{
809809
struct comnod *ac;
810810
char *cp, **argv, **argv0;
811-
int c;
811+
int c=-1;
812812
t->funct.functargs = ac = (struct comnod*)simple(lexp,SH_NOIO|SH_FUNDEF,NIL(struct ionod*));
813813
if(ac->comset || (ac->comtyp&COMSCAN))
814814
errormsg(SH_DICT,ERROR_exit(3),e_lexsyntax4,lexp->sh->inlineno);

src/cmd/ksh93/sh/xec.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@ int sh_exec(register const Shnode_t *t, int flags)
14261426
Namval_t node;
14271427
#endif /* SHOPT_NAMESPACE */
14281428
struct Namref nr;
1429-
long mode;
1429+
long mode = 0;
14301430
register struct slnod *slp;
14311431
if(!np->nvalue.ip)
14321432
{
@@ -1771,8 +1771,8 @@ int sh_exec(register const Shnode_t *t, int flags)
17711771
* don't create a new process, just
17721772
* save and restore io-streams
17731773
*/
1774-
pid_t pid;
1775-
int jmpval, waitall;
1774+
pid_t pid = 0;
1775+
int jmpval, waitall = 0;
17761776
int simple = (t->fork.forktre->tre.tretyp&COMMSK)==TCOM;
17771777
struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt));
17781778
if(shp->subshell)
@@ -2162,7 +2162,7 @@ int sh_exec(register const Shnode_t *t, int flags)
21622162
Shnode_t *tt = t->wh.whtre;
21632163
#if SHOPT_FILESCAN
21642164
Sfio_t *iop=0;
2165-
int savein;
2165+
int savein=-1;
21662166
#endif /*SHOPT_FILESCAN*/
21672167
#if SHOPT_OPTIMIZE
21682168
int jmpval = ((struct checkpt*)shp->jmplist)->mode;
@@ -2579,7 +2579,7 @@ int sh_exec(register const Shnode_t *t, int flags)
25792579
else
25802580
{
25812581
register int traceon=0;
2582-
register char *right;
2582+
register char *right = 0;
25832583
register char *trap;
25842584
char *argv[6];
25852585
n = type>>TSHIFT;
@@ -2613,7 +2613,7 @@ int sh_exec(register const Shnode_t *t, int flags)
26132613
}
26142614
else if(type&TBINARY)
26152615
{
2616-
char *op;
2616+
char *op = 0;
26172617
int pattern = 0;
26182618
if(trap || traceon)
26192619
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
32773277
int sh_fun(Namval_t *np, Namval_t *nq, char *argv[])
32783278
{
32793279
Shell_t *shp = sh_getinterp();
3280-
register int offset;
3280+
register int offset = 0;
32813281
register char *base;
32823282
Namval_t node;
32833283
struct Namref nr;
3284-
long mode;
3284+
long mode = 0;
32853285
char *prefix = shp->prefix;
32863286
int n=0;
32873287
char *av[3];

src/lib/libast/sfio/sfstrtof.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ S2F_function(str, end) char* str; char** end;
211211
int decimal = 0;
212212
int thousand = 0;
213213
int part = 0;
214-
int back_part;
215-
S2F_batch back_n;
214+
int back_part = 0;
215+
S2F_batch back_n = 0;
216216
S2F_number v;
217217
S2F_number p;
218218
S2F_part_t parts[16];

src/lib/libast/sfio/sftable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int type; /* >0: scanf, =0: printf, -1: internal */
5353
#endif
5454
{
5555
int base, fmt, flags, dot, width, precis;
56-
ssize_t n_str, size;
56+
ssize_t n_str, size = 0;
5757
char *t_str, *sp;
5858
int v, n, skip, dollar, decimal, thousand;
5959
Sffmt_t savft;

src/lib/libast/sfio/sfvprintf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ char* form; /* format to use */
101101
va_list args; /* arg list if !argf */
102102
#endif
103103
{
104-
int n, v, w, k, n_s, base, fmt, flags;
104+
int n, v=0, w, k, n_s, base, fmt, flags;
105105
Sflong_t lv;
106106
char *sp, *ssp, *endsp, *ep, *endep;
107107
int dot, width, precis, sign, decpt;
@@ -129,7 +129,7 @@ va_list args; /* arg list if !argf */
129129
int decimal = 0, thousand = 0;
130130

131131
#if _has_multibyte
132-
wchar_t* wsp;
132+
wchar_t* wsp = 0;
133133
SFMBDCL(fmbs) /* state of format string */
134134
SFMBDCL(mbs) /* state of some string */
135135
#ifdef mbwidth

src/lib/libast/string/stropt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ stropt(const char* as, const void* tab, int siz, int(*f)(void*, const void*, int
6060
register char* v;
6161
register char* t;
6262
char** p;
63-
char* u;
63+
char* u = 0;
6464
char* x;
6565
char* e;
6666
int n;
6767
int ql;
6868
int qr;
69-
int qc;
69+
int qc = 0;
7070

7171
if (!as) n = 0;
7272
else if (!(x = s = strdup(as))) n = -1;

src/lib/libast/string/strtoi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,13 @@ S2I_function(a, e, base) const char* a; char** e; int base;
230230
#endif
231231
register S2I_unumber n;
232232
register S2I_unumber x;
233-
register int c;
233+
register int c = 0;
234234
register int shift;
235235
register unsigned char* p;
236236
register unsigned char* cv;
237237
unsigned char* b;
238238
unsigned char* k;
239-
S2I_unumber v;
239+
S2I_unumber v = 0;
240240
#if S2I_multiplier
241241
register int base;
242242
#endif

0 commit comments

Comments
 (0)