Changeset: 7b17994f0884 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7b17994f0884
Modified Files:
NT/monetdb_config.h.in
clients/mapiclient/ReadlineTools.c
clients/mapiclient/Tests/mclient--help.stable.err
clients/mapiclient/Tests/mclient--help.stable.err.Windows
clients/mapiclient/dump.c
clients/mapilib/mapi.c
clients/odbc/driver/SQLExecute.c
common/options/monet_options.c
common/stream/stream.c
common/utils/mutils.c
gdk/gdk_bbp.c
testing/Mtest.py.in
Branch: default
Log Message:
Merge with Jul2015 branch.
diffs (truncated from 487 to 300 lines):
diff --git a/NT/monetdb_config.h.in b/NT/monetdb_config.h.in
--- a/NT/monetdb_config.h.in
+++ b/NT/monetdb_config.h.in
@@ -49,6 +49,14 @@
#include <stddef.h>
#include <ws2tcpip.h>
+#include <sys/types.h>
+#include <stdio.h> /* NULL, printf etc. */
+#include <stdlib.h>
+#include <errno.h>
+#include <stdarg.h> /* va_alist.. */
+
+#include <assert.h>
+
/* indicate to sqltypes.h that windows.h has already been included and
that it doesn't have to define Windows constants */
#define ALREADY_HAVE_WINDOWS_TYPE 1
@@ -995,9 +1003,37 @@
/* #undef size_t */
#if _MSC_VER < 1900
-#ifndef snprintf
-#define snprintf _snprintf
-#endif
+#define snprintf c99_snprintf
+#define vsnprintf c99_vsnprintf
+
+/* Microsoft _snprintf returns -1 and does not null-terminate when the
+ * buffer is too small, so work around that */
+
+static inline int
+c99_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap)
+{
+ int count = -1;
+
+ if (size != 0)
+ count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);
+ if (count == -1)
+ count = _vscprintf(format, ap);
+
+ return count;
+}
+
+static inline int
+c99_snprintf(char *outBuf, size_t size, const char *format, ...)
+{
+ int count;
+ va_list ap;
+
+ va_start(ap, format);
+ count = c99_vsnprintf(outBuf, size, format, ap);
+ va_end(ap);
+
+ return count;
+}
#endif
/* type used by connect */
@@ -1020,20 +1056,6 @@ typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned __int64 uint64_t;
-#if _MSC_VER < 1500
-#ifndef vsnprintf
-#define vsnprintf _vsnprintf
-#endif
-#endif
-
-#include <sys/types.h>
-#include <stdio.h> /* NULL, printf etc. */
-#include <stdlib.h>
-#include <errno.h>
-#include <stdarg.h> /* va_alist.. */
-
-#include <assert.h>
-
/* normally defined in stdbool.h, but that doesn't exist on Windows */
#define true 1
#define false 0
diff --git a/clients/mapiclient/ReadlineTools.c
b/clients/mapiclient/ReadlineTools.c
--- a/clients/mapiclient/ReadlineTools.c
+++ b/clients/mapiclient/ReadlineTools.c
@@ -61,12 +61,16 @@ sql_tablename_generator(const char *text
static MapiHdl table_hdl;
if (!state) {
- char query[512];
+ char *query;
seekpos = 0;
len = strlen(text);
- snprintf(query, sizeof(query), "SELECT t.\"name\", s.\"name\"
FROM \"sys\".\"tables\" t, \"sys\".\"schemas\" s where t.schema_id = s.id AND
t.\"name\" like '%s%%'", text);
- if ((table_hdl = mapi_query(_mid, query)) == NULL ||
mapi_error(_mid)) {
+ if ((query = malloc(len + 128)) == NULL)
+ return NULL;
+ snprintf(query, len + 128, "SELECT t.\"name\", s.\"name\" FROM
\"sys\".\"tables\" t, \"sys\".\"schemas\" s where t.schema_id = s.id AND
t.\"name\" like '%s%%'", text);
+ table_hdl = mapi_query(_mid, query);
+ free(query);
+ if (table_hdl == NULL || mapi_error(_mid)) {
if (table_hdl) {
mapi_explain_query(table_hdl, stderr);
mapi_close_handle(table_hdl);
@@ -176,7 +180,7 @@ static char *mal_commands[] = {
static int
mal_help(int cnt, int key)
{
- char *name, *c, buf[512];
+ char *name, *c, *buf;
int seekpos = 0, rowcount;
MapiHdl table_hdl;
@@ -188,8 +192,12 @@ mal_help(int cnt, int key)
c--;
while (c > rl_line_buffer && !isspace(*c))
c--;
- snprintf(buf, sizeof(buf), "manual.help(\"%s\");", c);
- if ((table_hdl = mapi_query(_mid, buf)) == NULL || mapi_error(_mid)) {
+ if ((buf = malloc(strlen(c) + 20)) == NULL)
+ return 0;
+ snprintf(buf, strlen(c) + 20, "manual.help(\"%s\");", c);
+ table_hdl = mapi_query(_mid, buf);
+ free(buf);
+ if (table_hdl == NULL || mapi_error(_mid)) {
if (table_hdl) {
mapi_explain_query(table_hdl, stderr);
mapi_close_handle(table_hdl);
@@ -220,7 +228,7 @@ mal_command_generator(const char *text,
static int idx;
static int seekpos, len, rowcount;
static MapiHdl table_hdl;
- char *name, buf[512];
+ char *name, *buf;
/* we pick our own portion of the linebuffer */
text = rl_line_buffer + strlen(rl_line_buffer) - 1;
@@ -250,14 +258,18 @@ mal_command_generator(const char *text,
text = c + 2;
while (isspace((int) *text))
text++;
+ if ((buf = malloc(strlen(text) + 32)) == NULL)
+ return NULL;
if (strchr(text, '.') == NULL)
- snprintf(buf, sizeof(buf),
+ snprintf(buf, strlen(text) + 32,
"manual.completion(\"%s.*(\");", text);
else
- snprintf(buf, sizeof(buf),
+ snprintf(buf, strlen(text) + 32,
"manual.completion(\"%s(\");", text);
seekpos = 0;
- if ((table_hdl = mapi_query(_mid, buf)) == NULL ||
mapi_error(_mid)) {
+ table_hdl = mapi_query(_mid, buf);
+ free(buf);
+ if (table_hdl == NULL || mapi_error(_mid)) {
if (table_hdl) {
mapi_explain_query(table_hdl, stderr);
mapi_close_handle(table_hdl);
diff --git a/clients/mapiclient/Tests/mclient--help.stable.err
b/clients/mapiclient/Tests/mclient--help.stable.err
--- a/clients/mapiclient/Tests/mclient--help.stable.err
+++ b/clients/mapiclient/Tests/mclient--help.stable.err
@@ -38,7 +38,6 @@ SQL specific opions
-w nr | --width=nr for pagination
-D | --dump create an SQL dump
-N | --inserts use INSERT INTO statements when dumping
- -P | --progress show progress bar
The file argument can be - for stdin
# 18:57:57 >
diff --git a/clients/mapiclient/Tests/mclient--help.stable.err.Windows
b/clients/mapiclient/Tests/mclient--help.stable.err.Windows
--- a/clients/mapiclient/Tests/mclient--help.stable.err.Windows
+++ b/clients/mapiclient/Tests/mclient--help.stable.err.Windows
@@ -37,7 +37,6 @@ SQL specific opions
-w nr | --width=nr for pagination
-D | --dump create an SQL dump
-N | --inserts use INSERT INTO statements when dumping
- -P | --progress show progress bar
The file argument can be - for stdin
# 18:57:57 >
diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -212,7 +212,7 @@ dump_foreign_keys(Mapi mid, const char *
"fkt.name = '%s' "
"ORDER BY fkk.name, nr", schema, tname);
} else if (tid != NULL) {
- maxquerylen = 1024;
+ maxquerylen = 1024 + strlen(tid);
query = malloc(maxquerylen);
snprintf(query, maxquerylen,
"SELECT ps.name, " /* 0 */
@@ -529,6 +529,8 @@ dump_column_definition(Mapi mid, stream
maxquerylen = 1024;
if (tid == NULL)
maxquerylen += strlen(tname) + strlen(schema);
+ else
+ maxquerylen += strlen(tid);
if ((query = malloc(maxquerylen)) == NULL)
goto bailout;
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -1918,7 +1918,7 @@ mapi_new(void)
Mapi
mapi_mapiuri(const char *url, const char *user, const char *pass, const char
*lang)
{
- char uri[8096];
+ char *uri;
char *host;
int port;
char *dbname;
@@ -1961,12 +1961,13 @@ mapi_mapiuri(const char *url, const char
}
/* copy to a writable working buffer */
- snprintf(uri, 8096, "%s", url + sizeof("mapi:monetdb://") - 1);
+ uri = strdup(url + sizeof("mapi:monetdb://") - 1);
if (uri[0] != '/') {
if ((p = strchr(uri, ':')) == NULL) {
mapi_setError(mid, "URI must contain a port number
after "
"the hostname", "mapi_mapiuri", MERROR);
+ free(uri);
return mid;
}
*p++ = '\0';
@@ -1990,6 +1991,7 @@ mapi_mapiuri(const char *url, const char
if (port <= 0) {
mapi_setError(mid, "URI contains invalid port",
"mapi_mapiuri", MERROR);
+ free(uri);
return mid;
}
} else {
@@ -2029,6 +2031,7 @@ mapi_mapiuri(const char *url, const char
mid->database = strdup(dbname);
set_uri(mid);
+ free(uri);
return mid;
}
@@ -2128,7 +2131,8 @@ mapi_mapi(const char *host, int port, co
while ((e = readdir(d)) != NULL) {
if (strncmp(e->d_name, ".s.monetdb.",
11) != 0)
continue;
- snprintf(buf, sizeof(buf), "/tmp/%s",
e->d_name);
+ if (snprintf(buf, sizeof(buf),
"/tmp/%s", e->d_name) >= sizeof(buf))
+ continue; /* ignore long name */
if (stat(buf, &st) != -1 &&
S_ISSOCK(st.st_mode))
socks[i++] = atoi(e->d_name +
11);
if (i == sizeof(socks))
@@ -2320,7 +2324,8 @@ parse_uri_query(Mapi mid, char *uri)
static void
set_uri(Mapi mid)
{
- char uri[1024];
+ size_t urilen = strlen(mid->hostname) + (mid->database ?
strlen(mid->database) : 0) + 32;
+ char *uri = malloc(urilen);
/* uri looks as follows:
* mapi:monetdb://host:port/database
@@ -2330,25 +2335,25 @@ set_uri(Mapi mid)
if (mid->database != NULL) {
if (mid->hostname[0] == '/') {
- snprintf(uri, sizeof(uri),
"mapi:monetdb://%s?database=%s",
- mid->hostname, mid->database);
+ snprintf(uri, urilen, "mapi:monetdb://%s?database=%s",
+ mid->hostname, mid->database);
} else {
- snprintf(uri, sizeof(uri), "mapi:monetdb://%s:%d/%s",
- mid->hostname, mid->port,
mid->database);
+ snprintf(uri, urilen, "mapi:monetdb://%s:%d/%s",
+ mid->hostname, mid->port, mid->database);
}
} else {
if (mid->hostname[0] == '/') {
- snprintf(uri, sizeof(uri), "mapi:monetdb://%s",
- mid->hostname);
+ snprintf(uri, urilen, "mapi:monetdb://%s",
+ mid->hostname);
} else {
- snprintf(uri, sizeof(uri), "mapi:monetdb://%s:%d",
- mid->hostname, mid->port);
+ snprintf(uri, urilen, "mapi:monetdb://%s:%d",
+ mid->hostname, mid->port);
}
}
if (mid->uri != NULL)
free(mid->uri);
- mid->uri = strdup(uri);
+ mid->uri = uri;
}
/* (Re-)establish a connection with the server. */
@@ -2661,7 +2666,7 @@ mapi_start_talking(Mapi mid)
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list