Re: bin/ksh: fix possible use of uninitialized variable

2011-03-16 Thread Theo de Raadt
I don't see any warnings.  Please show them.

If gcc is being fooled by loops, then this is because gcc is stupid.
it you show the warnings we can judge it.

In particular, the slen one looks totally bogus.

 This diff fixes uninitialized variable warnings emitted by gcc 4.2.1
 on i386/amd64.
 
 Index: eval.c
 ===
 RCS file: /cvs/src/bin/ksh/eval.c,v
 retrieving revision 1.35
 diff -u -p -r1.35 eval.c
 --- eval.c24 Mar 2010 08:27:26 -  1.35
 +++ eval.c14 Mar 2011 03:05:10 -
 @@ -159,6 +159,8 @@ expand(char *cp,  /* input word */
   int make_magic;
   size_t len;
  
 + x.split = 0;
 + x.str = NULL;
   if (cp == NULL)
   internal_errorf(1, expand(NULL));
   /* for alias, readonly, set, typeset commands */
 @@ -267,6 +269,7 @@ expand(char *cp,  /* input word */
   int stype;
   int slen;
  
 + slen = -1;
   sp = strchr(sp, '\0') + 1; /* skip variable */
   type = varsub(x, varname, sp, stype, slen);
   if (type  0) {



Re: bin/ksh: fix possible use of uninitialized variable

2011-03-16 Thread Okan Demirmen
On Wed 2011.03.16 at 12:30 -0600, Theo de Raadt wrote:
 I don't see any warnings.  Please show them.

ksh builds with -Wall by default, so these were emitted:

/home/okan/hack/open/ksh/ksh-current/eval.c: In function 'expand':
/home/okan/hack/open/ksh/ksh-current/eval.c:155: warning: 'x.split' may
be used uninitialized in this function
/home/okan/hack/open/ksh/ksh-current/eval.c:155: warning: 'x.str' may be
used uninitialized in this function
/home/okan/hack/open/ksh/ksh-current/eval.c:268: warning: 'slen' may be
used uninitialized in this function

 If gcc is being fooled by loops, then this is because gcc is stupid.
 it you show the warnings we can judge it.
 
 In particular, the slen one looks totally bogus.

  This diff fixes uninitialized variable warnings emitted by gcc 4.2.1
  on i386/amd64.
  
  Index: eval.c
  ===
  RCS file: /cvs/src/bin/ksh/eval.c,v
  retrieving revision 1.35
  diff -u -p -r1.35 eval.c
  --- eval.c  24 Mar 2010 08:27:26 -  1.35
  +++ eval.c  14 Mar 2011 03:05:10 -
  @@ -159,6 +159,8 @@ expand(char *cp,/* input word */
  int make_magic;
  size_t len;
   
  +   x.split = 0;
  +   x.str = NULL;
  if (cp == NULL)
  internal_errorf(1, expand(NULL));
  /* for alias, readonly, set, typeset commands */
  @@ -267,6 +269,7 @@ expand(char *cp,/* input word */
  int stype;
  int slen;
   
  +   slen = -1;
  sp = strchr(sp, '\0') + 1; /* skip variable */
  type = varsub(x, varname, sp, stype, slen);
  if (type  0) {



Re: bin/ksh: fix possible use of uninitialized variable

2011-03-14 Thread Okan Demirmen
On Mon 2011.03.14 at 11:05 +0800, Kevin Lo wrote:
 This diff fixes uninitialized variable warnings emitted by gcc 4.2.1
 on i386/amd64.

How's this instead (lifted from mksh)?

Index: eval.c
===
RCS file: /home/okan/hack/open/cvs/src/bin/ksh/eval.c,v
retrieving revision 1.35
diff -u -p -r1.35 eval.c
--- eval.c  24 Mar 2010 08:27:26 -  1.35
+++ eval.c  14 Mar 2011 07:09:37 -
@@ -152,7 +152,10 @@ expand(char *cp,   /* input word */
char *dp, *sp;  /* dest., source */
int fdo, word;  /* second pass flags; have word */
int doblank;/* field splitting of parameter/command subst */
-   Expand x;   /* expansion variables */
+   Expand x = {
+   /* expansion variables */
+   NULL, { NULL }, NULL, 0
+   };
SubType st_head, *st;
int newlines = 0; /* For trailing newlines in COMSUB */
int saw_eq, tilde_ok;
@@ -265,7 +268,7 @@ expand(char *cp,/* input word */
{
char *varname = ++sp; /* skip the { or x (}) */
int stype;
-   int slen;
+   int slen = 0;
 
sp = strchr(sp, '\0') + 1; /* skip variable */
type = varsub(x, varname, sp, stype, slen);



bin/ksh: fix possible use of uninitialized variable

2011-03-13 Thread Kevin Lo
This diff fixes uninitialized variable warnings emitted by gcc 4.2.1
on i386/amd64.

Index: eval.c
===
RCS file: /cvs/src/bin/ksh/eval.c,v
retrieving revision 1.35
diff -u -p -r1.35 eval.c
--- eval.c  24 Mar 2010 08:27:26 -  1.35
+++ eval.c  14 Mar 2011 03:05:10 -
@@ -159,6 +159,8 @@ expand(char *cp,/* input word */
int make_magic;
size_t len;
 
+   x.split = 0;
+   x.str = NULL;
if (cp == NULL)
internal_errorf(1, expand(NULL));
/* for alias, readonly, set, typeset commands */
@@ -267,6 +269,7 @@ expand(char *cp,/* input word */
int stype;
int slen;
 
+   slen = -1;
sp = strchr(sp, '\0') + 1; /* skip variable */
type = varsub(x, varname, sp, stype, slen);
if (type  0) {