Re: [PATCH] awk: initialisation of struct

2013-01-06 Thread Michael W. Bombardieri
On Thu, Jan 03, 2013 at 09:23:50PM -0800, Philip Guenther wrote:
 On Thu, Jan 3, 2013 at 8:48 PM, Michael W. Bombardieri m...@ii.net wrote:
  I am submitting a patch for awk. struct Cell has 7 fields;
  the final field is an optional next pointer.
 ...
  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
 
 Patches to awk should be sent to the upstream maintainer listed in
 /usr/src/usr.bin/awk/README
 
 (I would tend to defer to that person's opinion on points of C style...)
 

bwk@ got back to me. He will include this style change in awk.

 
 Philip Guenther



[PATCH] awk: initialisation of struct

2013-01-03 Thread Michael W. Bombardieri
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 -  1.33
+++ run.c   4 Jan 2013 04:42:15 -
@@ -73,23 +73,23 @@
 Node   *winner = NULL; /* root of parse tree */
 Cell   *tmps;  /* free temporary cells for execution */
 
-static Celltruecell={ OBOOL, BTRUE, 0, 0, 1.0, NUM };
+static Celltruecell={ OBOOL, BTRUE, NULL, NULL, 1.0, NUM, NULL };
 Cell   *True   = truecell;
-static Cellfalsecell   ={ OBOOL, BFALSE, 0, 0, 0.0, NUM };
+static Cellfalsecell   ={ OBOOL, BFALSE, NULL, NULL, 0.0, NUM, NULL };
 Cell   *False  = falsecell;
-static Cellbreakcell   ={ OJUMP, JBREAK, 0, 0, 0.0, NUM };
+static Cellbreakcell   ={ OJUMP, JBREAK, NULL, NULL, 0.0, NUM, NULL };
 Cell   *jbreak = breakcell;
-static Cellcontcell={ OJUMP, JCONT, 0, 0, 0.0, NUM };
+static Cellcontcell={ OJUMP, JCONT, NULL, NULL, 0.0, NUM, NULL };
 Cell   *jcont  = contcell;
-static Cellnextcell={ OJUMP, JNEXT, 0, 0, 0.0, NUM };
+static Cellnextcell={ OJUMP, JNEXT, NULL, NULL, 0.0, NUM, NULL };
 Cell   *jnext  = nextcell;
-static Cellnextfilecell={ OJUMP, JNEXTFILE, 0, 0, 0.0, NUM };
+static Cellnextfilecell={ OJUMP, JNEXTFILE, NULL, NULL, 0.0, NUM, NULL 
};
 Cell   *jnextfile  = nextfilecell;
-static Cellexitcell={ OJUMP, JEXIT, 0, 0, 0.0, NUM };
+static Cellexitcell={ OJUMP, JEXIT, NULL, NULL, 0.0, NUM, NULL };
 Cell   *jexit  = exitcell;
-static Cellretcell ={ OJUMP, JRET, 0, 0, 0.0, NUM };
+static Cellretcell ={ OJUMP, JRET, NULL, NULL, 0.0, NUM, NULL };
 Cell   *jret   = retcell;
-static Celltempcell={ OCELL, CTEMP, 0, , 0.0, NUM|STR|DONTFREE };
+static Celltempcell={ 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;



Re: [PATCH] awk: initialisation of struct

2013-01-03 Thread Philip Guenther
On Thu, Jan 3, 2013 at 8:48 PM, Michael W. Bombardieri m...@ii.net wrote:
 I am submitting a patch for awk. struct Cell has 7 fields;
 the final field is an optional next pointer.
...
 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

Patches to awk should be sent to the upstream maintainer listed in
/usr/src/usr.bin/awk/README

(I would tend to defer to that person's opinion on points of C style...)


Philip Guenther