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

Modified Files:
      Tag: XQuery_0-22
        array.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: array.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/mem/array.c,v
retrieving revision 1.24.6.2
retrieving revision 1.24.6.3
diff -u -d -r1.24.6.2 -r1.24.6.3
--- array.c     22 Feb 2008 10:39:22 -0000      1.24.6.2
+++ array.c     22 Feb 2008 15:13:15 -0000      1.24.6.3
@@ -223,7 +223,7 @@
      * ever larger buffers until we do know the size.
      */
     va_copy(tmp, mat);
-    while ((nchars = vsnprintf (try, len-1, fmt, tmp)) < 0) {
+    while ((nchars = vsnprintf (try, len, fmt, tmp)) < 0) {
         len *= 2;
         try = realloc(try, len);
         va_copy(tmp, mat);
@@ -234,7 +234,7 @@
     /* now that we know the actual size, print the formatted material
      * into the array (+ 1 for the trailing '\0' printed by vsprintf)
      */
-    (void) vsprintf ((char *) PFarray_nadd (a, nchars + 1), fmt, mat);
+    (void) vsnprintf ((char *) PFarray_nadd (a, nchars + 1), nchars + 1, fmt, 
mat);
 
     
     /* overwrite trailing '\0' on next print to this array */


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