Changeset: dcd409c0b03b for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=dcd409c0b03b
Modified Files:
clients/examples/C/smack01.c
clients/mapiclient/mclient.c
clients/mapiclient/tomograph.c
clients/odbc/driver/SQLDriverConnect.c
gdk/gdk_imprints.c
gdk/gdk_search.c
monetdb5/mal/mal_runtime.c
monetdb5/modules/kernel/bat5.c
monetdb5/modules/mal/groupby.c
sql/backends/monet5/sql.c
sql/common/sql_types.c
sql/server/rel_psm.c
sql/server/rel_schema.c
sql/server/rel_updates.c
sql/storage/bat/bat_storage.c
sql/test/Users/Tests/schema.stable.err
tools/merovingian/daemon/controlrunner.c
tools/merovingian/daemon/discoveryrunner.c
tools/merovingian/daemon/multiplex-funnel.c
tools/merovingian/daemon/peering.c
Branch: Jan2014
Log Message:
Fixes of problems found by Coverity.
diffs (truncated from 439 to 300 lines):
diff --git a/clients/examples/C/smack01.c b/clients/examples/C/smack01.c
--- a/clients/examples/C/smack01.c
+++ b/clients/examples/C/smack01.c
@@ -67,10 +67,13 @@ main(int argc, char **argv)
port = atol(argv[1]);
dbh = mapi_connect("localhost", port, "monetdb", "monetdb", l, NULL);
+ if (dbh == NULL || mapi_error(dbh))
+ die(dbh, hdl);
+
for (i = 0; i < 1000; i++) {
/* printf("setup connection %d\n", i); */
mapi_reconnect(dbh);
- if (dbh == NULL || mapi_error(dbh))
+ if (mapi_error(dbh))
die(dbh, hdl);
/* switch of autocommit */
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -709,7 +709,7 @@ CSVrenderer(MapiHdl hdl)
mnstr_write(toConsole, "\"", 1, 1);
} else
mnstr_printf(toConsole, "%s%s",
- i == 0 ? "" : sep, s ? s : "");
+ i == 0 ? "" : sep, s);
}
mnstr_printf(toConsole, "\n");
}
diff --git a/clients/mapiclient/tomograph.c b/clients/mapiclient/tomograph.c
--- a/clients/mapiclient/tomograph.c
+++ b/clients/mapiclient/tomograph.c
@@ -1626,7 +1626,7 @@ update(int state, int thread, lng clktic
return;
}
- if (state == DONE && strncmp(fcn, "profiler.tomograph", 18) == 0) {
+ if (state == DONE && fcn && strncmp(fcn, "profiler.tomograph", 18) ==
0) {
#ifdef _DEBUG_TOMOGRAPH_
fprintf(stderr, "Profiler.tomograph ends %d\n", batch);
#endif
@@ -1887,6 +1887,8 @@ processFile(char *fname)
s = open_rastream(fname);
if (s == NULL || mnstr_errnr(s)) {
fprintf(stderr,"ERROR Can not access '%s'\n",fname);
+ if (s)
+ mnstr_destroy(s);
return;
}
len = 0;
@@ -1909,7 +1911,7 @@ processFile(char *fname)
} else
len = 0;
}
- mnstr_close(s);
+ close_stream(s);
}
static void
diff --git a/clients/odbc/driver/SQLDriverConnect.c
b/clients/odbc/driver/SQLDriverConnect.c
--- a/clients/odbc/driver/SQLDriverConnect.c
+++ b/clients/odbc/driver/SQLDriverConnect.c
@@ -326,7 +326,7 @@ SQLDriverConnect_(ODBCDbc *dbc,
getenv("ODBCDEBUG") == NULL) {
if (ODBCdebug)
free((void *) ODBCdebug); /* discard const */
- ODBCdebug = strdup(attr);
+ ODBCdebug = attr;
#endif
} else
free(attr);
diff --git a/gdk/gdk_imprints.c b/gdk/gdk_imprints.c
--- a/gdk/gdk_imprints.c
+++ b/gdk/gdk_imprints.c
@@ -662,16 +662,16 @@ do {
GDKerror("#BATimprints: memory allocation error");
HEAPfree(imprints->bins);
GDKfree(imprints->bins);
- if (imprints->imps->filename != NULL) {
- GDKfree(imprints->imps->filename);
- }
- if (imprints->dict->filename != NULL) {
- GDKfree(imprints->dict->filename);
- }
if (imprints->imps != NULL) {
+ if (imprints->imps->filename != NULL) {
+ GDKfree(imprints->imps->filename);
+ }
GDKfree(imprints->imps);
}
if (imprints->dict != NULL) {
+ if (imprints->dict->filename != NULL) {
+ GDKfree(imprints->dict->filename);
+ }
GDKfree(imprints->dict);
}
GDKfree(imprints);
diff --git a/gdk/gdk_search.c b/gdk/gdk_search.c
--- a/gdk/gdk_search.c
+++ b/gdk/gdk_search.c
@@ -218,10 +218,11 @@ HASHcollisions(BAT *b, Hash *h)
{
lng cnt, entries = 0, max = 0;
double total = 0;
- BUN p, i, j, nil = HASHnil(h);
+ BUN p, i, j, nil;
if (b == 0 || h == 0)
return;
+ nil = HASHnil(h);
for (i = 0, j = h->mask; i <= j; i++)
if ((p = HASHget(h, i)) != nil) {
entries++;
@@ -560,15 +561,18 @@ HASHgonebad(BAT *b, const void *v)
static BUN
SORTfndwhich(BAT *b, const void *v, int which)
{
- BUN lo = BUNfirst(b), hi = BUNlast(b), mid;
+ BUN lo, hi, mid;
int cmp = 1;
BUN cur = BUN_NONE;
- BATiter bi = bat_iterator(b);
+ BATiter bi;
BUN diff, end;
if (b == NULL || (!b->tsorted && !b->trevsorted))
return BUN_NONE;
+ lo = BUNfirst(b);
+ hi = BUNlast(b);
+ bi = bat_iterator(b);
if (BATtdense(b)) {
/* no need for binary search on dense column */
if (*(const oid *) v < b->tseqbase)
diff --git a/monetdb5/mal/mal_runtime.c b/monetdb5/mal/mal_runtime.c
--- a/monetdb5/mal/mal_runtime.c
+++ b/monetdb5/mal/mal_runtime.c
@@ -289,13 +289,13 @@ updateFootPrint(MalBlkPtr mb, MalStkPtr
if (b == NULL || isVIEW(b) || b->batPersistence == PERSISTENT)
return;
cnt = BATcount(b);
- if( b->H ) total += heapinfo(&b->H->heap);
- if( b->H ) total += heapinfo(b->H->vheap);
+ total += heapinfo(&b->H->heap);
+ total += heapinfo(b->H->vheap);
- if ( b->T ) total += heapinfo(&b->T->heap);
- if ( b->T ) total += heapinfo(b->T->vheap);
- if ( b->H ) total += hashinfo(b->H->hash);
- if ( b->T ) total += hashinfo(b->T->hash);
+ total += heapinfo(&b->T->heap);
+ total += heapinfo(b->T->vheap);
+ total += hashinfo(b->H->hash);
+ total += hashinfo(b->T->hash);
BBPreleaseref(b->batCacheid);
// no concurrency protection (yet)
stk->tmpspace += total/1024/1024; // keep it in MBs
diff --git a/monetdb5/modules/kernel/bat5.c b/monetdb5/modules/kernel/bat5.c
--- a/monetdb5/modules/kernel/bat5.c
+++ b/monetdb5/modules/kernel/bat5.c
@@ -97,7 +97,7 @@ local_utoa(size_t i)
return buf;
}
-#define COLLISION 64
+#define COLLISION (8 * sizeof(size_t))
static void
HASHinfo(BAT *bk, BAT *bv, Hash *h, str s)
@@ -105,14 +105,14 @@ HASHinfo(BAT *bk, BAT *bv, Hash *h, str
BUN i;
BUN j;
BUN k;
- BUN cnt[COLLISION + 2];
+ BUN cnt[COLLISION + 1];
BUNappend(bk, pre(s, "type"), FALSE);
BUNappend(bv, ATOMname(h->type),FALSE);
BUNappend(bk, pre(s, "mask"), FALSE);
BUNappend(bv, local_utoa(h->lim),FALSE);
- for (i = 0; i <= COLLISION + 1; i++) {
+ for (i = 0; i < COLLISION + 1; i++) {
cnt[i] = 0;
}
for (i = 0; i <= h->mask; i++) {
@@ -122,9 +122,9 @@ HASHinfo(BAT *bk, BAT *bv, Hash *h, str
cnt[k]++;
}
- for (i = 0; i <= COLLISION + 1; i++)
+ for (i = 0; i < COLLISION + 1; i++)
if (cnt[i]) {
- BUNappend(bk, pre(s, local_itoa((ssize_t)
(i?(((ssize_t)1)<<(i-1)):0))), FALSE);
+ BUNappend(bk, pre(s,
local_utoa(i?(((size_t)1)<<(i-1)):0)), FALSE);
BUNappend(bv, local_utoa((size_t) cnt[i]), FALSE);
}
}
diff --git a/monetdb5/modules/mal/groupby.c b/monetdb5/modules/mal/groupby.c
--- a/monetdb5/modules/mal/groupby.c
+++ b/monetdb5/modules/mal/groupby.c
@@ -104,13 +104,15 @@ GROUPcollect( Client cntxt, MalBlkPtr mb
bs = BATsample( b, sample);
if (bs) {
bh = BATkunique(BATmirror(bs));
- a->unique[a->last] = BATcount(bh);
- if ( bh ) BBPreleaseref(bh->batCacheid);
+ if (bh) {
+ a->unique[a->last] = BATcount(bh);
+ BBPreleaseref(bh->batCacheid);
+ }
+ BBPreleaseref(bs->batCacheid);
}
if ( b->tsorted)
a->unique[a->last] = 1000; /* sorting helps grouping */
a->size = BATcount(b);
- if ( bs ) BBPreleaseref(bs->batCacheid);
}
#ifdef _DEBUG_GROUPBY_
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -2672,9 +2672,10 @@ mvc_import_table_wrap(Client cntxt, MalB
#else
s = bstream_create(ss, 0x2000000);
#endif
- if (s != NULL)
+ if (s != NULL) {
b = mvc_import_table(cntxt, be->mvc, s, *sname, *tname, (char
*) tsep, (char *) rsep, (char *) ssep, (char *) ns, *sz, *offset, *locked);
- bstream_destroy(s);
+ bstream_destroy(s);
+ }
GDKfree(filename);
GDKfree(tsep);
GDKfree(rsep);
diff --git a/sql/common/sql_types.c b/sql/common/sql_types.c
--- a/sql/common/sql_types.c
+++ b/sql/common/sql_types.c
@@ -710,7 +710,7 @@ sql_bind_member(sql_allocator *sa, sql_s
}
}
}
- if (tp->type->eclass == EC_NUM) {
+ if (tp && tp->type->eclass == EC_NUM) {
/* add second round but now look for Decimals only */
for (n = funcs->h; n; n = n->next) {
sql_func *f = n->data;
diff --git a/sql/server/rel_psm.c b/sql/server/rel_psm.c
--- a/sql/server/rel_psm.c
+++ b/sql/server/rel_psm.c
@@ -894,9 +894,11 @@ rel_drop_func(mvc *sql, dlist *qname, dl
}
}
list_destroy(list_func);
+ list_destroy(type_list);
return sql_error(sql, 02, "DROP %s%s: no such
%s%s '%s' (%s)", KF, F, kf, f, name, arg_list);
}
list_destroy(list_func);
+ list_destroy(type_list);
return sql_error(sql, 02, "DROP %s%s: no such %s%s '%s'
()", KF, F, kf, f, name);
} else {
@@ -904,13 +906,13 @@ rel_drop_func(mvc *sql, dlist *qname, dl
}
} else if (((is_func && type != F_FILT) && !func->res.type) ||
(!is_func && func->res.type)) {
- if (list_func)
- list_destroy(list_func);
+ list_destroy(list_func);
+ list_destroy(type_list);
return sql_error(sql, 02, "DROP %s%s: cannot drop %s '%s'", KF,
F, is_func?"procedure":"function", name);
}
- if (list_func)
- list_destroy(list_func);
+ list_destroy(list_func);
+ list_destroy(type_list);
return rel_drop_function(sql->sa, s->base.name, name, func->base.id,
type, drop_action);
}
diff --git a/sql/server/rel_schema.c b/sql/server/rel_schema.c
--- a/sql/server/rel_schema.c
+++ b/sql/server/rel_schema.c
@@ -1518,7 +1518,7 @@ rel_create_index(mvc *sql, char *iname,
sname = get_schema_name( sql, sname, tname);
nt = dup_sql_table(sql->sa, t);
- if (t->persistence != SQL_DECLARED_TABLE && s)
+ if (t->persistence != SQL_DECLARED_TABLE)
sname = s->base.name;
if (t->s && !nt->s)
nt->s = t->s;
diff --git a/sql/server/rel_updates.c b/sql/server/rel_updates.c
--- a/sql/server/rel_updates.c
+++ b/sql/server/rel_updates.c
@@ -648,8 +648,10 @@ rel_update_join_idx(mvc *sql, sql_idx *i
rnll_exps = rnl;
}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list