Update of /cvsroot/monetdb/pathfinder/compiler/sql
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv30146/compiler/sql
Modified Files:
Tag: XQuery_0-22
sql.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: sql.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/sql/sql.c,v
retrieving revision 1.48.4.2
retrieving revision 1.48.4.3
diff -u -d -r1.48.4.2 -r1.48.4.3
--- sql.c 22 Feb 2008 10:39:28 -0000 1.48.4.2
+++ sql.c 22 Feb 2008 15:13:17 -0000 1.48.4.3
@@ -1230,7 +1230,7 @@
default:
{
size_t len = sizeof ("t0000");
- char *res = (char *) PFmalloc (len+1);
+ char *res = (char *) PFmalloc (len);
/* to express table names we use
* the following format:
* t[0-9][0-9][0-9][0-9]
@@ -1240,6 +1240,7 @@
assert (name < 10000);
snprintf (res, len, "t%04u", name);
+ res[len - 1] = 0;
return res;
}
}
@@ -1261,7 +1262,7 @@
default:
{
size_t len = sizeof ("a0000");
- char *res = (char *) PFmalloc (len+1);
+ char *res = (char *) PFmalloc (len);
/* to express alias names we use
* the following format:
* a[0-9][0-9][0-9][0-9]
@@ -1271,6 +1272,7 @@
assert (name < 10000);
snprintf (res, len, "a%04u", name);
+ res[len - 1] = 0;
return res;
}
}
@@ -1314,8 +1316,9 @@
case sql_col_max: return "max";
case sql_col_dist:
assert (name->ty < 100);
- res = (char *) PFmalloc (8);
+ res = (char *) PFmalloc (7);
snprintf (res, 7, "dist%02u", name->ty);
+ res[6] = 0;
return res;
}
else {
@@ -1323,8 +1326,9 @@
char *tystr = PFalg_simple_type_str (name->ty);
size_t len = strlen (attstr) + strlen (tystr) + 2;
- res = (char *) PFmalloc (len + 1);
+ res = (char *) PFmalloc (len);
snprintf (res, len, "%s_%s", attstr, tystr);
+ res[len - 1] = 0;
}
return res;
}
-------------------------------------------------------------------------
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