Changeset: fd4779d6f658 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=fd4779d6f658 Modified Files: gdk/gdk_tracer.h monetdb5/mal/mal_instruction.c monetdb5/mal/mal_prelude.c monetdb5/modules/mal/tablet.c sql/backends/monet5/rel_bin.c sql/backends/monet5/sql_execute.c sql/backends/monet5/sql_user.c sql/server/rel_dump.c sql/server/rel_semantic.c sql/server/rel_semantic.h sql/server/rel_updates.c sql/server/rel_updates.h Branch: Oct2020 Log Message:
Coverity inspired fixes. diffs (294 lines): diff --git a/gdk/gdk_tracer.h b/gdk/gdk_tracer.h --- a/gdk/gdk_tracer.h +++ b/gdk/gdk_tracer.h @@ -150,6 +150,10 @@ gdk_export log_level_t lvl_per_component GDKtracer_log(__FILE__, __func__, __LINE__, \ LOG_LEVEL, COMP, NULL, MSG, ##__VA_ARGS__) +#ifdef __COVERITY__ +/* hide this for static code analysis: too many false positives */ +#define GDK_TRACER_LOG(LOG_LEVEL, COMP, MSG, ...) ((void) 0) +#else #define GDK_TRACER_LOG(LOG_LEVEL, COMP, MSG, ...) \ do { \ if (GDK_TRACER_TEST(LOG_LEVEL, COMP)) { \ @@ -157,6 +161,7 @@ gdk_export log_level_t lvl_per_component ## __VA_ARGS__); \ } \ } while (0) +#endif #define TRC_CRITICAL(COMP, MSG, ...) \ diff --git a/monetdb5/mal/mal_instruction.c b/monetdb5/mal/mal_instruction.c --- a/monetdb5/mal/mal_instruction.c +++ b/monetdb5/mal/mal_instruction.c @@ -246,7 +246,7 @@ freeMalBlk(MalBlkPtr mb) mb->help = 0; mb->inlineProp = 0; mb->unsafeProp = 0; - GDKfree(mb->errors); + freeException(mb->errors); GDKfree(mb); } diff --git a/monetdb5/mal/mal_prelude.c b/monetdb5/mal/mal_prelude.c --- a/monetdb5/mal/mal_prelude.c +++ b/monetdb5/mal/mal_prelude.c @@ -317,7 +317,6 @@ melFunction(bool command, char *mod, cha InstrPtr sig; va_list va; - va_start(va, argc); assert(mod); mod = putName(mod); c = getModule(mod); @@ -356,6 +355,7 @@ melFunction(bool command, char *mod, cha } } + va_start(va, argc); for (i = 0; i<retc; i++ ){ mel_func_arg a = va_arg(va, mel_func_arg); idx = makeFuncArgument(mb, &a); @@ -363,6 +363,7 @@ melFunction(bool command, char *mod, cha if (idx < 0 || sig == NULL) { freeInstruction(sig); freeSymbol(s); + va_end(va); return MEL_ERR; } int tpe = TYPE_any; @@ -384,6 +385,7 @@ melFunction(bool command, char *mod, cha if (idx < 0 || sig == NULL) { freeInstruction(sig); freeSymbol(s); + va_end(va); return MEL_ERR; } int tpe = TYPE_any; diff --git a/monetdb5/modules/mal/tablet.c b/monetdb5/modules/mal/tablet.c --- a/monetdb5/modules/mal/tablet.c +++ b/monetdb5/modules/mal/tablet.c @@ -878,7 +878,7 @@ SQLinsert_val(READERtask *task, int col, BUNappend(task->cntxt->error_fld, &col, false) != GDK_SUCCEED || BUNappend(task->cntxt->error_msg, buf, false) != GDK_SUCCEED || BUNappend(task->cntxt->error_input, err, false) != GDK_SUCCEED) { - freeException(err); + GDKfree(err); task->besteffort = 0; /* no longer best effort */ MT_lock_unset(&errorlock); return -1; @@ -886,7 +886,7 @@ SQLinsert_val(READERtask *task, int col, MT_lock_unset(&errorlock); } ret = -!task->besteffort; /* yep, two unary operators ;-) */ - freeException(err); + GDKfree(err); err = NULL; /* replace it with a nil */ adt = fmt->nildata; @@ -906,7 +906,7 @@ SQLinsert_val(READERtask *task, int col, (err = SQLload_error(task, idx,task->as->nr_attrs)) == NULL || BUNappend(task->cntxt->error_input, err, false) != GDK_SUCCEED) task->besteffort = 0; - freeException(err); + GDKfree(err); task->rowerror[idx]++; task->errorcnt++; MT_lock_unset(&errorlock); diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c --- a/sql/backends/monet5/rel_bin.c +++ b/sql/backends/monet5/rel_bin.c @@ -3572,7 +3572,7 @@ rel2bin_sample(backend *be, sql_rel *rel static stmt * sql_parse(backend *be, sql_schema *s, const char *query, char mode) { - sql_rel *rel = rel_parse(be->mvc, s, (char*)query, mode); + sql_rel *rel = rel_parse(be->mvc, s, query, mode); stmt *sq = NULL; if ((rel = sql_processrelation(be->mvc, rel, 1, 1))) diff --git a/sql/backends/monet5/sql_execute.c b/sql/backends/monet5/sql_execute.c --- a/sql/backends/monet5/sql_execute.c +++ b/sql/backends/monet5/sql_execute.c @@ -380,12 +380,12 @@ SQLstatementIntern(Client c, const char m->reply_size = -2; /* do not clean up result tables */ /* mimic a client channel on which the query text is received */ - b = (buffer *) GDKmalloc(sizeof(buffer)); + b = malloc(sizeof(buffer)); if (b == NULL) { msg = createException(SQL,"sql.statement",SQLSTATE(HY013) MAL_MALLOC_FAIL); goto endofcompile; } - n = GDKmalloc(len + 1 + 1); + n = malloc(len + 1 + 1); if (n == NULL) { msg = createException(SQL,"sql.statement",SQLSTATE(HY013) MAL_MALLOC_FAIL); goto endofcompile; @@ -405,6 +405,7 @@ SQLstatementIntern(Client c, const char bs = bstream_create(buf, b->len); if (bs == NULL) { mnstr_destroy(buf); + buffer_destroy(b); b = NULL; msg = createException(SQL,"sql.statement",SQLSTATE(HY013) MAL_MALLOC_FAIL); goto endofcompile; @@ -560,8 +561,7 @@ endofcompile: c->sqlcontext = be; backend_destroy(sql); - GDKfree(n); - GDKfree(b); + buffer_destroy(b); bstream_destroy(m->scanner.rs); if (m->sa) sa_destroy(m->sa); diff --git a/sql/backends/monet5/sql_user.c b/sql/backends/monet5/sql_user.c --- a/sql/backends/monet5/sql_user.c +++ b/sql/backends/monet5/sql_user.c @@ -38,7 +38,7 @@ monet5_drop_user(ptr _mvc, str user) err = AUTHremoveUser(c, user); if (err !=MAL_SUCCEED) { (void) sql_error(m, 02, "DROP USER: %s", getExceptionMessage(err)); - _DELETE(err); + freeException(err); return FALSE; } sys = find_sql_schema(m->session->tr, "sys"); @@ -100,7 +100,7 @@ monet5_find_user(ptr mp, str user) str err; if ((err = AUTHgetUsers(&uid, &nme, c)) != MAL_SUCCEED) { - _DELETE(err); + freeException(err); return -1; } p = BUNfnd(nme, user); diff --git a/sql/server/rel_dump.c b/sql/server/rel_dump.c --- a/sql/server/rel_dump.c +++ b/sql/server/rel_dump.c @@ -971,7 +971,7 @@ exp_read(mvc *sql, sql_rel *lrel, sql_re } for (node *n = rexps->h; n; n = n->next){ sql_exp *e = n->data; - + list_append(tl, exp_subtype(e)); } @@ -1526,7 +1526,7 @@ rel_read(mvc *sql, char *r, int *pos, li if (!update_allowed(sql, t, t->base.name, "TRUNCATE", "truncate", 2)) return NULL; - return rel_truncate(sql->sa, lrel, drop_action, restart_sequences); + return rel_truncate(sql->sa, lrel, restart_sequences, drop_action); } if (r[*pos] == 'u' && r[*pos+1] == 'p' && r[*pos+2] == 'd') { diff --git a/sql/server/rel_semantic.c b/sql/server/rel_semantic.c --- a/sql/server/rel_semantic.c +++ b/sql/server/rel_semantic.c @@ -24,7 +24,7 @@ #include <ctype.h> sql_rel * -rel_parse(mvc *m, sql_schema *s, char *query, char emode) +rel_parse(mvc *m, sql_schema *s, const char *query, char emode) { mvc o = *m; sql_rel *rel = NULL; @@ -42,17 +42,15 @@ rel_parse(mvc *m, sql_schema *s, char *q if (s) m->session->schema = s; - if (!(b = (buffer*)GDKmalloc(sizeof(buffer)))) + if ((b = malloc(sizeof(buffer))) == NULL) return NULL; - n = GDKmalloc(len + 1 + 1); - if (!n) { - GDKfree(b); + if ((n = malloc(len + 1 + 1)) == NULL) { + free(b); return NULL; } snprintf(n, len + 2, "%s\n", query); - query = n; len++; - buffer_init(b, query, len); + buffer_init(b, n, len); buf = buffer_rastream(b, "sqlstatement"); if(buf == NULL) { buffer_destroy(b); @@ -78,8 +76,7 @@ rel_parse(mvc *m, sql_schema *s, char *q qc = query_create(m); rel = rel_semantic(qc, m->sym); - GDKfree(query); - GDKfree(b); + buffer_destroy(b); bstream_destroy(m->scanner.rs); m->sym = NULL; diff --git a/sql/server/rel_semantic.h b/sql/server/rel_semantic.h --- a/sql/server/rel_semantic.h +++ b/sql/server/rel_semantic.h @@ -17,7 +17,6 @@ #include "sql_query.h" extern sql_rel *rel_semantic(sql_query *query, symbol *sym); -extern sql_rel *rel_parse(mvc *m, sql_schema *s, char *query, char emode); +extern sql_rel *rel_parse(mvc *m, sql_schema *s, const char *query, char emode); #endif /*_REL_SEMANTIC_H_*/ - 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 @@ -1887,18 +1887,17 @@ rel_parse_val(mvc *m, char *query, sql_s m->qc = NULL; m->emode = emode; - b = (buffer*)GDKmalloc(sizeof(buffer)); + b = malloc(sizeof(buffer)); len += 8; /* add 'select ;' */ - n = GDKmalloc(len + 1 + 1); + n = malloc(len + 1 + 1); if(!b || !n) { - GDKfree(b); - GDKfree(n); + free(b); + free(n); return NULL; } snprintf(n, len + 2, "select %s;\n", query); - query = n; len++; - buffer_init(b, query, len); + buffer_init(b, n, len); s = buffer_rastream(b, "sqlstatement"); if(!s) { buffer_destroy(b); @@ -1933,8 +1932,7 @@ rel_parse_val(mvc *m, char *query, sql_s e = exp_check_type(m, tpe, from, e, type_cast); } } - GDKfree(query); - GDKfree(b); + buffer_destroy(b); bstream_destroy(m->scanner.rs); m->sym = NULL; diff --git a/sql/server/rel_updates.h b/sql/server/rel_updates.h --- a/sql/server/rel_updates.h +++ b/sql/server/rel_updates.h @@ -20,7 +20,7 @@ extern sql_rel *rel_update(mvc *sql, sql sql_export sql_rel *rel_insert(mvc *sql, sql_rel *t, sql_rel *inserts); extern sql_rel *rel_delete(sql_allocator *sa, sql_rel *t, sql_rel *deletes); -extern sql_rel *rel_truncate(sql_allocator *sa, sql_rel *t, int drop_action, int check_identity); +extern sql_rel *rel_truncate(sql_allocator *sa, sql_rel *t, int restart_sequences, int drop_action); extern sql_exp *rel_parse_val(mvc *m, char *query, sql_subtype *tpe, char emode, sql_rel *from); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list