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

Modified Files:
      Tag: XQuery_0-22
        core.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: core.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/core/core.c,v
retrieving revision 1.57.6.1
retrieving revision 1.57.6.2
diff -u -d -r1.57.6.1 -r1.57.6.2
--- core.c      22 Feb 2008 10:39:20 -0000      1.57.6.1
+++ core.c      22 Feb 2008 15:13:14 -0000      1.57.6.2
@@ -164,7 +164,7 @@
 PFvar_t *
 PFcore_new_var (char *prefix)
 {
-    char                vname[VNAME_MAX+1];
+    char                vname[VNAME_MAX];
     int                 l;
 
     /* prefix may not exceed 4 characters */
@@ -172,16 +172,17 @@
 
     /* construct new var name */
     if (prefix)
-        l = snprintf (vname, sizeof(vname)-1, "%3s_%04u", prefix, core_vars);
+        l = snprintf (vname, sizeof(vname), "%s_%04u", prefix, core_vars);
     else
-        l = snprintf (vname, sizeof(vname)-1, "v_%04u", core_vars);
+        l = snprintf (vname, sizeof(vname), "v_%04u", core_vars);
+    vname[sizeof(vname)-1] = 0;
     
     /* warn if we needed to truncate the variable name
      * (this does not affect the correct core mapping but may
      * confuse the user)
      */
     if ((PFstate.print_dot || PFstate.print_pretty) && 
-        ((size_t) l >= VNAME_MAX || l < 0))
+        ((size_t) l >= sizeof(vname) || l < 0))
         PFinfo (OOPS_NOTICE, "truncated variable name `%s' in core query",
                 vname);
 


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