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

Modified Files:
      Tag: XQuery_0-22
        mil.c mil_opt.c milprint_summer.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: mil.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/mil/mil.c,v
retrieving revision 1.51
retrieving revision 1.51.2.1
diff -u -d -r1.51 -r1.51.2.1
--- mil.c       31 Jan 2008 21:43:33 -0000      1.51
+++ mil.c       22 Feb 2008 10:39:23 -0000      1.51.2.1
@@ -354,7 +354,7 @@
             name -= PF_MIL_RES_VAR_COUNT;
             assert (name < 10000);
             size_t len = sizeof ("a0000");
-            char *res = PFmalloc (len);
+            char *res = PFmalloc (len+1);
             snprintf (res, len, "a%04u", name);
             return res;
         }

Index: mil_opt.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/mil/mil_opt.c,v
retrieving revision 1.31
retrieving revision 1.31.6.1
diff -u -d -r1.31 -r1.31.6.1
--- mil_opt.c   11 Jan 2008 10:47:10 -0000      1.31
+++ mil_opt.c   22 Feb 2008 10:39:23 -0000      1.31.6.1
@@ -899,7 +899,7 @@
 int milprintf(opt_t *o, const char *format, ...)
 {
         int j, i = strlen(format) + 80;
-        char *milbuf = INTERN_MALLOC(i);
+        char *milbuf = INTERN_MALLOC(i+1);
         va_list ap;
 
        if (milbuf == NULL) return -1;
@@ -908,14 +908,14 @@
         va_start(ap, format);
         j = vsnprintf(milbuf, i, format, ap);
         va_end (ap);
-        while (j < 0 || j > i) {
+        while (j < 0 || j >= i) {
                 int old_i = i;
                 if (j > 0)      /* C99 */
                         i = j + 1;
                 else            /* old C */
                         i *= 2;
 
-                milbuf = INTERN_REALLOC(milbuf, old_i, i);
+                milbuf = INTERN_REALLOC(milbuf, old_i+1, i+1);
                if (milbuf == NULL) return -1;
 
                 va_start(ap, format);

Index: milprint_summer.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/mil/milprint_summer.c,v
retrieving revision 1.409
retrieving revision 1.409.6.1
diff -u -d -r1.409 -r1.409.6.1
--- milprint_summer.c   11 Jan 2008 10:47:10 -0000      1.409
+++ milprint_summer.c   22 Feb 2008 10:39:24 -0000      1.409.6.1
@@ -126,20 +126,20 @@
 static void mps_error(const char *format, ...)
 {
     int j, i = strlen(format) + 80;
-    char *msg = PFmalloc(i);
+    char *msg = PFmalloc(i+1);
     va_list ap;
 
     /* take in a block of MIL statements */
     va_start(ap, format);
     j = vsnprintf(msg, i, format, ap);
     va_end (ap);
-    while (j < 0 || j > i) {
+    while (j < 0 || j >= i) {
             int old_i = i;
             if (j > 0)      /* C99 */
                     i = j + 1;
             else            /* old C */
                     i *= 2;
-            msg = PFrealloc(msg, old_i, i);
+            msg = PFrealloc(msg, old_i+1, i+1);
             va_start(ap, format);
             j = vsnprintf(msg, i, format, ap);
             va_end (ap);
@@ -5273,7 +5273,7 @@
             cur_level);
 
     char buf[128];
-    snprintf(buf, sizeof(buf),
+    snprintf(buf, sizeof(buf)-1,
             "fn:replace (string?, string, string%s) as string",
             hasFlags?", string":"");
 
@@ -6096,15 +6096,15 @@
         && !(res->kind == c_var && res->sem.var == LLL(snd)->sem.var)) /* see 
query11 hack below */
     {
         /* cannot be pushed below theta-join, as 'snd_iter.[lng]()' is needed 
for 'addValues' (below) */
-        snprintf(rx,32,"nil");
-        snprintf(order_snd,128,
+        snprintf(rx,sizeof(rx)-1,"nil");
+        snprintf(order_snd,sizeof(order_snd)-1,
                 "var order_snd := 
snd_iter.leftfetchjoin(iter%03u.reverse());\n",
                 snd_var);
     }
     else
     {
-        snprintf(rx,32,"iter%03u.reverse()",snd_var);
-        snprintf(order_snd,128,
+        snprintf(rx,sizeof(rx)-1,"iter%03u.reverse()",snd_var);
+        snprintf(order_snd,sizeof(order_snd)-1,
                 "var order_snd := snd_iter; 
#.leftfetchjoin(iter%03u.reverse()); pushed below theta-join\n",
                 snd_var);
     }


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