Update of /cvsroot/monetdb/pathfinder/src/sqlhelpers/xmlshred
In directory
sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv30146/src/sqlhelpers/xmlshred
Modified Files:
Tag: XQuery_0-22
encoding.c main.c oops.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: encoding.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/src/sqlhelpers/xmlshred/encoding.c,v
retrieving revision 1.20.6.1
retrieving revision 1.20.6.2
diff -u -d -r1.20.6.1 -r1.20.6.2
--- encoding.c 22 Feb 2008 10:39:34 -0000 1.20.6.1
+++ encoding.c 22 Feb 2008 15:13:22 -0000 1.20.6.2
@@ -709,7 +709,8 @@
(void) ctx;
va_start (az, msg);
- vsnprintf (buf, buf_size - 1, msg, az);
+ vsnprintf (buf, buf_size, msg, az);
+ buf[buf_size - 1] = 0;
fprintf (err, "%s", buf);
va_end (az);
Index: oops.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/src/sqlhelpers/xmlshred/oops.c,v
retrieving revision 1.5
retrieving revision 1.5.6.1
diff -u -d -r1.5 -r1.5.6.1
--- oops.c 11 Jan 2008 10:47:23 -0000 1.5
+++ oops.c 22 Feb 2008 15:13:22 -0000 1.5.6.1
@@ -49,11 +49,13 @@
char puffer[PUFFER_SIZE+1];
vsnprintf (puffer, PUFFER_SIZE, fmt, az);
+ puffer[PUFFER_SIZE] = 0;
if (err) {
emsg = strerror (errmsg);
snprintf (puffer+strlen(puffer),
- PUFFER_SIZE - strlen (emsg),
- ": %s", emsg);
+ PUFFER_SIZE - strlen (puffer),
+ ": %s", emsg);
+ puffer[PUFFER_SIZE] = 0;
}
fflush(stdout); /* if stdout and stderr are equal */
/* write everything in the puffer to stderr */
Index: main.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/src/sqlhelpers/xmlshred/main.c,v
retrieving revision 1.12.6.1
retrieving revision 1.12.6.2
diff -u -d -r1.12.6.1 -r1.12.6.2
--- main.c 22 Feb 2008 10:39:35 -0000 1.12.6.1
+++ main.c 22 Feb 2008 15:13:22 -0000 1.12.6.2
@@ -101,9 +101,11 @@
sizeof (long_options) /
sizeof (struct option) - 1,
sizeof (struct option),
- cmp_opt)))
- return snprintf (buf, sizeof (opt_buf) - 1, t, l->name), buf;
- else
+ cmp_opt))) {
+ snprintf (buf, sizeof (opt_buf), t, l->name);
+ buf[sizeof(opt_buf) - 1] = 0;
+ return buf;
+ } else
return "";
}
@@ -287,7 +289,8 @@
if (status.attributes_separate) {
/* attribute file */
char attoutfile[FILENAME_MAX];
- snprintf (attoutfile, FILENAME_MAX-1, "%s_atts.csv",
status.outfile);
+ snprintf (attoutfile, FILENAME_MAX, "%s_atts.csv", status.outfile);
+ attoutfile[sizeof(attoutfile) - 1] = 0;
attout = SHopen_write (attoutfile);
}
@@ -295,22 +298,26 @@
/* names file */
char namesoutfile[FILENAME_MAX];
char urisoutfile[FILENAME_MAX];
- snprintf (namesoutfile, FILENAME_MAX-1, "%s_names.csv",
status.outfile);
+ snprintf (namesoutfile, FILENAME_MAX, "%s_names.csv",
status.outfile);
+ namesoutfile[sizeof(namesoutfile) - 1] = 0;
namesout = SHopen_write (namesoutfile);
- snprintf (urisoutfile, FILENAME_MAX-1, "%s_uris.csv",
status.outfile);
+ snprintf (urisoutfile, FILENAME_MAX, "%s_uris.csv",
status.outfile);
+ urisoutfile[sizeof(urisoutfile) - 1] = 0;
urisout = SHopen_write (urisoutfile);
}
if (status.statistics) {
/* guide file */
char guideoutfile[FILENAME_MAX];
- snprintf (guideoutfile, FILENAME_MAX-1, "%s_guide.xml",
status.outfile);
+ snprintf (guideoutfile, FILENAME_MAX, "%s_guide.xml",
status.outfile);
+ guideoutfile[sizeof(guideoutfile) - 1] = 0;
guideout = SHopen_write (guideoutfile);
}
/* encoding file */
char outfile[FILENAME_MAX];
- snprintf (outfile, FILENAME_MAX-1, "%s.csv", status.outfile);
+ snprintf (outfile, FILENAME_MAX, "%s.csv", status.outfile);
+ outfile[sizeof(outfile) - 1] = 0;
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