Update of /cvsroot/monetdb/pathfinder/src/sqlhelpers/xmlshred
In directory 
sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv21153/src/sqlhelpers/xmlshred

Modified Files:
      Tag: XQuery_0-22
        encoding.c main.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: encoding.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/src/sqlhelpers/xmlshred/encoding.c,v
retrieving revision 1.20
retrieving revision 1.20.6.1
diff -u -d -r1.20 -r1.20.6.1
--- encoding.c  11 Jan 2008 10:47:23 -0000      1.20
+++ encoding.c  22 Feb 2008 10:39:34 -0000      1.20.6.1
@@ -690,7 +690,7 @@
 
     if (bufpos < 0 || (unsigned int) bufpos < text_size) {
         snprintf ((char *) buf + bufpos,
-                  MIN (n, BUF_SIZE - bufpos) + 1,
+                  MIN (n, BUF_SIZE - bufpos),
                   "%s",
                   (char *) chars);
         bufpos += MIN (n, BUF_SIZE - bufpos);
@@ -709,7 +709,7 @@
     (void) ctx;
 
     va_start (az, msg);
-    vsnprintf (buf, buf_size, msg, az);
+    vsnprintf (buf, buf_size - 1, msg, az);
     fprintf (err, "%s", buf);
     va_end (az);
 

Index: main.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/src/sqlhelpers/xmlshred/main.c,v
retrieving revision 1.12
retrieving revision 1.12.6.1
diff -u -d -r1.12 -r1.12.6.1
--- main.c      11 Jan 2008 14:43:27 -0000      1.12
+++ main.c      22 Feb 2008 10:39:35 -0000      1.12.6.1
@@ -102,7 +102,7 @@
                                             sizeof (struct option) - 1,
                                         sizeof (struct option),
                                         cmp_opt)))
-        return snprintf (buf, sizeof (opt_buf), t, l->name), buf;
+        return snprintf (buf, sizeof (opt_buf) - 1, t, l->name), buf;
     else
         return "";
 }
@@ -287,7 +287,7 @@
         if (status.attributes_separate) {
             /* attribute file */
             char attoutfile[FILENAME_MAX];
-            snprintf (attoutfile, FILENAME_MAX, "%s_atts.csv", status.outfile);
+            snprintf (attoutfile, FILENAME_MAX-1, "%s_atts.csv", 
status.outfile);
             attout = SHopen_write (attoutfile);
         }
     
@@ -295,22 +295,22 @@
             /* names file */
             char namesoutfile[FILENAME_MAX];
             char urisoutfile[FILENAME_MAX];
-            snprintf (namesoutfile, FILENAME_MAX, "%s_names.csv", 
status.outfile);
+            snprintf (namesoutfile, FILENAME_MAX-1, "%s_names.csv", 
status.outfile);
             namesout = SHopen_write (namesoutfile);
-            snprintf (urisoutfile, FILENAME_MAX, "%s_uris.csv", 
status.outfile);
+            snprintf (urisoutfile, FILENAME_MAX-1, "%s_uris.csv", 
status.outfile);
             urisout = SHopen_write (urisoutfile);
         }
     
         if (status.statistics) {
             /* guide file */
             char guideoutfile[FILENAME_MAX];
-            snprintf (guideoutfile, FILENAME_MAX, "%s_guide.xml", 
status.outfile);
+            snprintf (guideoutfile, FILENAME_MAX-1, "%s_guide.xml", 
status.outfile);
             guideout = SHopen_write (guideoutfile);
         }
 
         /* encoding file */
         char outfile[FILENAME_MAX];
-        snprintf (outfile, FILENAME_MAX, "%s.csv", status.outfile);
+        snprintf (outfile, FILENAME_MAX-1, "%s.csv", status.outfile);
         shout = SHopen_write (outfile);
     }
     else


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