Update of /cvsroot/monetdb/pathfinder/compiler/debug
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv21153/compiler/debug

Modified Files:
      Tag: XQuery_0-22
        abssynprint.c coreprint.c 
Log Message:
This is a fix for bug [ 1892554 ] PF: loading pre-compiled MIL modules
fails on Windows

There seems to a difference between Windows and Linux in the meaning
of the second argument of snprintf and vsnprintf: in Linux this
argument gives the size of the buffer to which the function writes,
whereas in Windows it gives the number of non-NULL bytes that it can
write (and then it adds a NULL).  This means that on Windows you have
to specify a size which is *smaller* than the actual size of the
buffer.

To make the same code work on both flavors, in some cases we now
overallocate the needed space by one byte so that we can use
(sizeof(buf)-1) as size.


Index: coreprint.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/debug/coreprint.c,v
retrieving revision 1.42
retrieving revision 1.42.6.1
diff -u -d -r1.42 -r1.42.6.1
--- coreprint.c 11 Jan 2008 10:47:01 -0000      1.42
+++ coreprint.c 22 Feb 2008 10:39:21 -0000      1.42.6.1
@@ -155,11 +155,11 @@
 static char     label[32];
 
 /** Print node with no content */
-#define L0(t)           snprintf (label, 32, (t))
+#define L0(t)           snprintf (label, sizeof(label)-1, (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)-1, "%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)-1, "%s [%s,%s]", (l1), 
(l2), (l3))
 
 /**
  * Print core language tree in AT&T dot notation.
@@ -171,26 +171,26 @@
 core_dot (FILE *f, PFcnode_t *n, char *node)
 {
     int c;
-    char s[sizeof ("4294967285")];
+    char s[sizeof ("4294967285") + 1];
     
     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), "%s", PFesc_string (n->sem.str));
+        snprintf (s, sizeof (s) - 1, "%s", PFesc_string (n->sem.str));
         L2 (c_id[n->kind], s);
         break;
     case c_lit_int:   
-        snprintf (s, sizeof (s), LLFMT, n->sem.num);
+        snprintf (s, sizeof (s) - 1, LLFMT, n->sem.num);
         L2 (c_id[n->kind], s);                  
         break;
     case c_lit_dec:   
-        snprintf (s, sizeof (s), "%.5g", n->sem.dec);
+        snprintf (s, sizeof (s) - 1, "%.5g", n->sem.dec);
         L2 (c_id[n->kind], s);                
         break;
     case c_lit_dbl:   
-        snprintf (s, sizeof (s), "%.5g", n->sem.dbl);
+        snprintf (s, sizeof (s) - 1, "%.5g", n->sem.dbl);
         L2 (c_id[n->kind], s);                
         break;
     case c_apply:     

Index: abssynprint.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/debug/abssynprint.c,v
retrieving revision 1.39
retrieving revision 1.39.6.1
diff -u -d -r1.39 -r1.39.6.1
--- abssynprint.c       11 Jan 2008 10:47:01 -0000      1.39
+++ abssynprint.c       22 Feb 2008 10:39:21 -0000      1.39.6.1
@@ -250,27 +250,27 @@
 static char     label[DOT_LABELS];
 
 /** Print node with no content */
-#define L(t, loc)           snprintf (label, DOT_LABELS,                    \
+#define L(t, loc)           snprintf (label, sizeof(label)-1,                  
  \
                                      "%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, DOT_LABELS,                    \
+#define L2(l1, l2, loc)     snprintf (label, sizeof(label)-1,                  
  \
                                      "%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, DOT_LABELS,                    \
+#define L3(l1, l2, l3, loc) snprintf (label, sizeof(label)-1,                  
  \
                                       "%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, DOT_LABELS,                \
+#define L4(l1, l2, l3, l4, loc) snprintf (label, sizeof(label)-1,              
  \
                                       "%s [%s,%s,%s]\\n(%u,%u-%u,%u)\\r",   \
                                       (l1), (l2), (l3), (l4),               \
                                       (loc).first_row, (loc).first_col,     \
@@ -286,19 +286,19 @@
 abssyn_dot (FILE *f, PFpnode_t *n, char *node, bool qnames_resolved)
 {
     int c;
-    char s[sizeof ("4294967285")];
+    char s[sizeof ("4294967285") + 1];
 
     switch (n->kind) {
         case p_lit_int:
-            snprintf (s, sizeof (s), LLFMT, n->sem.num);
+            snprintf (s, sizeof (s) - 1, LLFMT, n->sem.num);
             L2 (p_id[n->kind], s, n->loc);
             break;
         case p_lit_dec:
-            snprintf (s, sizeof (s), "%.5g", n->sem.dec);
+            snprintf (s, sizeof (s) - 1, "%.5g", n->sem.dec);
             L2 (p_id[n->kind], s, n->loc);
             break;
         case p_lit_dbl:
-            snprintf (s, sizeof (s), "%.5g", n->sem.dbl);
+            snprintf (s, sizeof (s) - 1, "%.5g", n->sem.dbl);
             L2 (p_id[n->kind], s, n->loc);
             break;
         case p_lit_str:


-------------------------------------------------------------------------
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

Reply via email to