Hi,

I am submitting a patch for awk. "struct Cell" has 7 fields;
the final field is an optional "next" pointer.

 79 typedef struct Cell {
 80     uschar  ctype;      /* OCELL, OBOOL, OJUMP, etc. */
 81     uschar  csub;       /* CCON, CTEMP, CFLD, etc. */
 82     char    *nval;      /* name, for variables only */
 83     char    *sval;      /* string value */
 84     Awkfloat fval;      /* value as number */
 85     int  tval;      /* type info: STR|NUM|ARR|FCN|FLD|CON|DONTFREE */
 86     struct Cell *cnext; /* ptr to next if chained */
 87 } Cell;

Splint identified that instances of Cell are initialised with only 6
fields, e.g.

run.c:78:24: Initializer block for falsecell has 6 fields, but Cell has 7
                fields: 2, 12, 0, 0, 0.0, 01

The following patch adds the 7th element as a NULL pointer to next list
element. Also, make Cell.nval and Cell.sval use NULL instead of 0.

- Michael


Index: run.c
===================================================================
RCS file: /cvs/src/usr.bin/awk/run.c,v
retrieving revision 1.33
diff -u -r1.33 run.c
--- run.c       28 Sep 2011 19:27:18 -0000      1.33
+++ run.c       4 Jan 2013 04:42:15 -0000
@@ -73,23 +73,23 @@
 Node   *winner = NULL; /* root of parse tree */
 Cell   *tmps;          /* free temporary cells for execution */
 
-static Cell    truecell        ={ OBOOL, BTRUE, 0, 0, 1.0, NUM };
+static Cell    truecell        ={ OBOOL, BTRUE, NULL, NULL, 1.0, NUM, NULL };
 Cell   *True   = &truecell;
-static Cell    falsecell       ={ OBOOL, BFALSE, 0, 0, 0.0, NUM };
+static Cell    falsecell       ={ OBOOL, BFALSE, NULL, NULL, 0.0, NUM, NULL };
 Cell   *False  = &falsecell;
-static Cell    breakcell       ={ OJUMP, JBREAK, 0, 0, 0.0, NUM };
+static Cell    breakcell       ={ OJUMP, JBREAK, NULL, NULL, 0.0, NUM, NULL };
 Cell   *jbreak = &breakcell;
-static Cell    contcell        ={ OJUMP, JCONT, 0, 0, 0.0, NUM };
+static Cell    contcell        ={ OJUMP, JCONT, NULL, NULL, 0.0, NUM, NULL };
 Cell   *jcont  = &contcell;
-static Cell    nextcell        ={ OJUMP, JNEXT, 0, 0, 0.0, NUM };
+static Cell    nextcell        ={ OJUMP, JNEXT, NULL, NULL, 0.0, NUM, NULL };
 Cell   *jnext  = &nextcell;
-static Cell    nextfilecell    ={ OJUMP, JNEXTFILE, 0, 0, 0.0, NUM };
+static Cell    nextfilecell    ={ OJUMP, JNEXTFILE, NULL, NULL, 0.0, NUM, NULL 
};
 Cell   *jnextfile      = &nextfilecell;
-static Cell    exitcell        ={ OJUMP, JEXIT, 0, 0, 0.0, NUM };
+static Cell    exitcell        ={ OJUMP, JEXIT, NULL, NULL, 0.0, NUM, NULL };
 Cell   *jexit  = &exitcell;
-static Cell    retcell         ={ OJUMP, JRET, 0, 0, 0.0, NUM };
+static Cell    retcell         ={ OJUMP, JRET, NULL, NULL, 0.0, NUM, NULL };
 Cell   *jret   = &retcell;
-static Cell    tempcell        ={ OCELL, CTEMP, 0, "", 0.0, NUM|STR|DONTFREE };
+static Cell    tempcell        ={ OCELL, CTEMP, NULL, "", 0.0, 
NUM|STR|DONTFREE, NULL };
 
 Node   *curnode = NULL;        /* the node being executed, for debugging */
 
@@ -224,7 +224,7 @@
 
 Cell *call(Node **a, int n)    /* function call.  very kludgy and fragile */
 {
-       static Cell newcopycell = { OCELL, CCOPY, 0, "", 0.0, NUM|STR|DONTFREE 
};
+       static Cell newcopycell = { OCELL, CCOPY, NULL, "", 0.0, 
NUM|STR|DONTFREE, NULL };
        int i, ncall, ndef;
        int freed = 0; /* handles potential double freeing when fcn & param 
share a tempcell */
        Node *x;

Reply via email to