Update of /cvsroot/monetdb/pathfinder/compiler/debug
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv30146/compiler/debug
Modified Files:
Tag: XQuery_0-22
abssynprint.c coreprint.c mildebug.c
Log Message:
Reevaluated the use of (v)snprintf.
On Windows, as on Linux, the size argument is the size of the buffer
to which is printed. The difference between Linux and Windows is that
on Linux if the data doesn't fit, the buffer is still NUL-terminated
(and truncated, obviously), but on Windows the data is truncated but
not NUL-terminated.
The upshot of this is that we can use the correctly-sized buffers, but
we must make sure that truncated buffers are properly NUL-terminated.
Index: mildebug.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/debug/Attic/mildebug.c,v
retrieving revision 1.14
retrieving revision 1.14.6.1
diff -u -d -r1.14 -r1.14.6.1
--- mildebug.c 11 Jan 2008 10:47:01 -0000 1.14
+++ mildebug.c 22 Feb 2008 15:13:14 -0000 1.14.6.1
@@ -87,11 +87,11 @@
static char label[32];
/** Print node with no content */
-#define L(t) snprintf (label, 32, t)
+#define L(t) snprintf (label, sizeof(label), t)
/** Print node with single content */
-#define L2(l1, l2) snprintf (label, 32, "%s [%s]", l1, l2)
+#define L2(l1, l2) snprintf (label, sizeof(label), "%s [%s]", l1, l2)
/** Print node with two content parts */
-#define L3(l1, l2, l3) snprintf (label, 32, "%s [%s,%s]", l1, l2, l3)
+#define L3(l1, l2, l3) snprintf (label, sizeof(label), "%s [%s,%s]", l1, l2,
l3)
/**
* Print MIL tree in AT&T dot notation.
@@ -110,24 +110,30 @@
case m_var: L2 (m_id[n->kind], PFqname_str (n->sem.var->qname));
break;
case m_lit_int: snprintf (s, sizeof (s), LLFMT, n->sem.num);
+ s[sizeof(s) - 1] = 0;
L2 (m_id[n->kind], s);
break;
case m_lit_str: snprintf (s, sizeof (s), "%s", n->sem.str);
+ s[sizeof(s) - 1] = 0;
L2 (m_id[n->kind], s);
break;
case m_lit_dbl: snprintf (s, sizeof (s), "%g", n->sem.dbl);
+ s[sizeof(s) - 1] = 0;
L2 (m_id[n->kind], s);
break;
case m_lit_bit: snprintf (s, sizeof (s),
"%s", n->sem.tru ? "true" : "false");
+ s[sizeof(s) - 1] = 0;
L2 (m_id[n->kind], s);
break;
case m_type: snprintf (s, sizeof (s), "%s", miltypes[n->mty.ty]);
+ s[sizeof(s) - 1] = 0;
L2 (m_id[n->kind], s);
break;
default: L (m_id[n->kind]);
}
+ label[sizeof(label) - 1] = 0;
fprintf (f, "%s [label=\"%s\"];\n", node, label);
Index: coreprint.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/debug/coreprint.c,v
retrieving revision 1.42.6.1
retrieving revision 1.42.6.2
diff -u -d -r1.42.6.1 -r1.42.6.2
--- coreprint.c 22 Feb 2008 10:39:21 -0000 1.42.6.1
+++ coreprint.c 22 Feb 2008 15:13:14 -0000 1.42.6.2
@@ -155,11 +155,11 @@
static char label[32];
/** Print node with no content */
-#define L0(t) snprintf (label, sizeof(label)-1, (t))
+#define L0(t) snprintf (label, sizeof(label), (t))
/** Print node with single content */
-#define L2(l1, l2) snprintf (label, sizeof(label)-1, "%s [%s]", (l1),
(l2))
+#define L2(l1, l2) snprintf (label, sizeof(label), "%s [%s]", (l1),
(l2))
/** Print node with two content parts */
-#define L3(l1, l2, l3) snprintf (label, sizeof(label)-1, "%s [%s,%s]", (l1),
(l2), (l3))
+#define L3(l1, l2, l3) snprintf (label, sizeof(label), "%s [%s,%s]", (l1),
(l2), (l3))
/**
* Print core language tree in AT&T dot notation.
@@ -171,26 +171,30 @@
core_dot (FILE *f, PFcnode_t *n, char *node)
{
int c;
- char s[sizeof ("4294967285") + 1];
+ char s[sizeof ("4294967285")];
switch (n->kind) {
case c_var:
L2 (c_id[n->kind], PFqname_str (n->sem.var->qname));
break;
case c_lit_str:
- snprintf (s, sizeof (s) - 1, "%s", PFesc_string (n->sem.str));
+ snprintf (s, sizeof (s), "%s", PFesc_string (n->sem.str));
+ s[sizeof(s) - 1] = 0;
L2 (c_id[n->kind], s);
break;
case c_lit_int:
- snprintf (s, sizeof (s) - 1, LLFMT, n->sem.num);
+ snprintf (s, sizeof (s), LLFMT, n->sem.num);
+ s[sizeof(s) - 1] = 0;
L2 (c_id[n->kind], s);
break;
case c_lit_dec:
- snprintf (s, sizeof (s) - 1, "%.5g", n->sem.dec);
+ snprintf (s, sizeof (s), "%.5g", n->sem.dec);
+ s[sizeof(s) - 1] = 0;
L2 (c_id[n->kind], s);
break;
case c_lit_dbl:
- snprintf (s, sizeof (s) - 1, "%.5g", n->sem.dbl);
+ snprintf (s, sizeof (s), "%.5g", n->sem.dbl);
+ s[sizeof(s) - 1] = 0;
L2 (c_id[n->kind], s);
break;
case c_apply:
@@ -217,6 +221,7 @@
L0 (c_id[n->kind]);
break;
}
+ label[sizeof(label) - 1] = 0;
fprintf (f, "%s [label=\"%s\"];\n", node, label);
Index: abssynprint.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/debug/abssynprint.c,v
retrieving revision 1.39.6.1
retrieving revision 1.39.6.2
diff -u -d -r1.39.6.1 -r1.39.6.2
--- abssynprint.c 22 Feb 2008 10:39:21 -0000 1.39.6.1
+++ abssynprint.c 22 Feb 2008 15:13:14 -0000 1.39.6.2
@@ -250,27 +250,27 @@
static char label[DOT_LABELS];
/** Print node with no content */
-#define L(t, loc) snprintf (label, sizeof(label)-1,
\
+#define L(t, loc) snprintf (label, sizeof(label),
\
"%s\\n(%u,%u-%u,%u)\\r", \
(t), (loc).first_row, (loc).first_col,\
(loc).last_row, (loc).last_col)
/** Print node with single content */
-#define L2(l1, l2, loc) snprintf (label, sizeof(label)-1,
\
+#define L2(l1, l2, loc) snprintf (label, sizeof(label),
\
"%s [%s]\\n(%u,%u-%u,%u)\\r", \
(l1), (l2), \
(loc).first_row, (loc).first_col, \
(loc).last_row, (loc).last_col)
/** Print node with two content parts */
-#define L3(l1, l2, l3, loc) snprintf (label, sizeof(label)-1,
\
+#define L3(l1, l2, l3, loc) snprintf (label, sizeof(label),
\
"%s [%s,%s]\\n(%u,%u-%u,%u)\\r", \
(l1), (l2), (l3), \
(loc).first_row, (loc).first_col, \
(loc).last_row, (loc).last_col)
/** Print node with two content parts */
-#define L4(l1, l2, l3, l4, loc) snprintf (label, sizeof(label)-1,
\
+#define L4(l1, l2, l3, l4, loc) snprintf (label, sizeof(label),
\
"%s [%s,%s,%s]\\n(%u,%u-%u,%u)\\r", \
(l1), (l2), (l3), (l4), \
(loc).first_row, (loc).first_col, \
@@ -290,15 +290,18 @@
switch (n->kind) {
case p_lit_int:
- snprintf (s, sizeof (s) - 1, LLFMT, n->sem.num);
+ snprintf (s, sizeof (s), LLFMT, n->sem.num);
+ s[sizeof(s) - 1] = 0;
L2 (p_id[n->kind], s, n->loc);
break;
case p_lit_dec:
- snprintf (s, sizeof (s) - 1, "%.5g", n->sem.dec);
+ snprintf (s, sizeof (s), "%.5g", n->sem.dec);
+ s[sizeof(s) - 1] = 0;
L2 (p_id[n->kind], s, n->loc);
break;
case p_lit_dbl:
- snprintf (s, sizeof (s) - 1, "%.5g", n->sem.dbl);
+ snprintf (s, sizeof (s), "%.5g", n->sem.dbl);
+ s[sizeof(s) - 1] = 0;
L2 (p_id[n->kind], s, n->loc);
break;
case p_lit_str:
@@ -387,6 +390,7 @@
default:
L (p_id[n->kind], n->loc);
}
+ label[sizeof(label)-1] = 0;
fprintf (f, "%s [label=\"%s\"];\n", node, label);
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Monetdb-pf-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-pf-checkins