Changeset: 4b3a6302b144 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/4b3a6302b144 Modified Files: gdk/gdk_bat.c gdk/gdk_batop.c gdk/gdk_bbp.c gdk/gdk_join.c gdk/gdk_logger.c gdk/gdk_logger_old.c monetdb5/mal/mal_authorize.c monetdb5/mal/mal_profiler.c monetdb5/modules/atoms/uuid.c monetdb5/modules/kernel/bat5.c monetdb5/modules/mal/clients.c monetdb5/modules/mal/mkey.c sql/backends/monet5/for.c sql/backends/monet5/sql.c sql/backends/monet5/sql_cast.c sql/backends/monet5/sql_cat.c sql/backends/monet5/sql_statement.c sql/backends/monet5/sql_user.c sql/backends/monet5/vaults/fits/fits.c sql/server/rel_unnest.c sql/storage/objectset.c sql/storage/store.c Branch: default Log Message:
Merge with Sep2022 branch. diffs (truncated from 1247 to 300 lines): diff --git a/clients/odbc/driver/ODBCUtil.c b/clients/odbc/driver/ODBCUtil.c --- a/clients/odbc/driver/ODBCUtil.c +++ b/clients/odbc/driver/ODBCUtil.c @@ -1214,6 +1214,8 @@ ODBCTranslateSQL(ODBCDbc *dbc, const SQL } } } + if (repl == NULL) + break; } size_t l = i + strlen(repl) + 2 + arglen + strlen(rest) - j + 1 + strlen(repl2) + repl3len; nquery = malloc(l); diff --git a/common/options/monet_options.c b/common/options/monet_options.c --- a/common/options/monet_options.c +++ b/common/options/monet_options.c @@ -139,8 +139,7 @@ mo_config_file(opt **Set, int setlen, ch val = strchr(s, '='); if (val == NULL) { fprintf(stderr, "mo_config_file: syntax error in %s at %s\n", file, s); - fclose(fd); - exit(1); + break; } *val = 0; @@ -162,8 +161,7 @@ mo_config_file(opt **Set, int setlen, ch } if (quote) { fprintf(stderr, "mo_config_file: wrong number of quotes in %s at %s\n", file, val); - fclose(fd); - exit(1); + break; } /* remove trailing white space */ while (isspace((unsigned char) t[-1])) @@ -176,7 +174,7 @@ mo_config_file(opt **Set, int setlen, ch opt *tmp = realloc(set, (setlen + 1) * sizeof(opt)); if (tmp == NULL) - return setlen; + break; *Set = set = tmp; set[setlen].kind = opt_config; set[setlen].name = strdup(s); @@ -184,7 +182,7 @@ mo_config_file(opt **Set, int setlen, ch if (set[setlen].name == NULL || set[setlen].value == NULL) { free(set[setlen].name); free(set[setlen].value); - return setlen; + break; } for (t = val, s = set[setlen].value; *t; t++) if (*t != '"') diff --git a/common/stream/memio.c b/common/stream/memio.c --- a/common/stream/memio.c +++ b/common/stream/memio.c @@ -59,8 +59,8 @@ buffer_get_buf(buffer *b) r[b->pos] = '\0'; b->buf = malloc(b->len); if (b->buf == NULL) { - free(b); - free(r); + /* restore b->buf */ + b->buf = r; return NULL; } b->len = b->buf ? b->len : 0; diff --git a/common/stream/url_stream.c b/common/stream/url_stream.c --- a/common/stream/url_stream.c +++ b/common/stream/url_stream.c @@ -171,16 +171,16 @@ open_urlstream(const char *url) return NULL; } s->stream_data.p = (void *) c; - curl_easy_setopt(c->handle, CURLOPT_URL, s->name); - curl_easy_setopt(c->handle, CURLOPT_WRITEDATA, s); - curl_easy_setopt(c->handle, CURLOPT_VERBOSE, 0); - curl_easy_setopt(c->handle, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(c->handle, CURLOPT_FAILONERROR, 1); - curl_easy_setopt(c->handle, CURLOPT_ERRORBUFFER, c->errbuf); - curl_easy_setopt(c->handle, CURLOPT_WRITEFUNCTION, write_callback); - CURLcode ret = curl_easy_perform(c->handle); - if (ret != CURLE_OK) { - if (strlen(c->errbuf) > 0) + CURLcode ret; + if ((ret = curl_easy_setopt(c->handle, CURLOPT_ERRORBUFFER, c->errbuf)) != CURLE_OK || + (ret = curl_easy_setopt(c->handle, CURLOPT_URL, s->name)) != CURLE_OK || + (ret = curl_easy_setopt(c->handle, CURLOPT_WRITEDATA, s)) != CURLE_OK || + (ret = curl_easy_setopt(c->handle, CURLOPT_VERBOSE, 0)) != CURLE_OK || + (ret = curl_easy_setopt(c->handle, CURLOPT_NOSIGNAL, 1)) != CURLE_OK || + (ret = curl_easy_setopt(c->handle, CURLOPT_FAILONERROR, 1)) != CURLE_OK || + (ret = curl_easy_setopt(c->handle, CURLOPT_WRITEFUNCTION, write_callback)) != CURLE_OK || + (ret = curl_easy_perform(c->handle)) != CURLE_OK) { + if (c->errbuf[0] != 0) mnstr_set_open_error(url, 0, "%s", c->errbuf); else mnstr_set_open_error(url, 0, "curl_easy_perform: %s", curl_easy_strerror(ret)); diff --git a/common/utils/mutils.c b/common/utils/mutils.c --- a/common/utils/mutils.c +++ b/common/utils/mutils.c @@ -797,12 +797,15 @@ MT_lockf(const char *filename, int mode) fd = fp->fd; free(fp); seek = lseek(fd, 4, SEEK_SET); + if (seek < 0) + seek = 0; /* should never happen, just for coverity */ int ret = lockf(fd, mode, 1); (void) lseek(fd, seek, SEEK_SET); /* move seek pointer back */ /* do not close fd, it is closed by caller */ return ret; /* 0 if unlock successful, -1 if not */ } } + pthread_mutex_unlock(&cs); } fd = open(filename, O_CREAT | O_RDWR | O_TEXT | O_CLOEXEC, MONETDB_MODE); diff --git a/common/utils/muuid.c b/common/utils/muuid.c --- a/common/utils/muuid.c +++ b/common/utils/muuid.c @@ -71,12 +71,18 @@ generateUUID(void) /* generate something like this: * cefa7a9c-1dd2-41b2-8350-880020adbeef * ("%08x-%04x-%04x-%04x-%012x") */ +#ifdef __COVERITY__ + /* avoid rand() when checking with coverity */ + snprintf(out, sizeof(out), + "00000000-0000-0000-0000-000000000000"); +#else snprintf(out, sizeof(out), "%04x%04x-%04x-4%03x-8%03x-%04x%04x%04x", (unsigned) rand() & 0xFFFF, (unsigned) rand() & 0xFFFF, (unsigned) rand() & 0xFFFF, (unsigned) rand() & 0x0FFF, (unsigned) rand() & 0x0FFF, (unsigned) rand() & 0xFFFF, (unsigned) rand() & 0xFFFF, (unsigned) rand() & 0xFFFF); +#endif } return strdup(out); } diff --git a/common/utils/ripemd160.c b/common/utils/ripemd160.c --- a/common/utils/ripemd160.c +++ b/common/utils/ripemd160.c @@ -27,19 +27,21 @@ RIPEMD160Input(RIPEMD160Context *ctxt, c ctxt->length += bytecount; if (ctxt->noverflow > 0) { + assert(ctxt->noverflow < 64); if (ctxt->noverflow + bytecount < 64) { memcpy(ctxt->overflow + ctxt->noverflow, bytes, bytecount); ctxt->noverflow += bytecount; return; } - memcpy(ctxt->overflow + ctxt->noverflow, bytes, bytecount - ctxt->noverflow); + unsigned l = 64 - ctxt->noverflow; + memcpy(ctxt->overflow + ctxt->noverflow, bytes, l); const uint8_t *x = ctxt->overflow; for (int i = 0; i < 16; i++) { X[i] = BYTES_TO_DWORD(x); x += 4; } - bytecount -= ctxt->noverflow; - bytes += ctxt->noverflow; + bytecount -= l; + bytes += l; ctxt->noverflow = 0; MDcompress(ctxt->digest, X); } diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c --- a/gdk/gdk_bat.c +++ b/gdk/gdk_bat.c @@ -649,7 +649,14 @@ BATclear(BAT *b, bool force) BAThseqbase(b, 0); BATtseqbase(b, ATOMtype(b->ttype) == TYPE_oid ? 0 : oid_nil); b->theap->dirty = true; - BATsettrivprop(b); + b->tnonil = true; + b->tnil = false; + b->tsorted = b->trevsorted = ATOMlinear(b->ttype); + b->tnosorted = b->tnorevsorted = 0; + b->tkey = true; + b->tnokey[0] = b->tnokey[1] = 0; + b->tminpos = b->tmaxpos = BUN_NONE; + b->tunique_est = 0; MT_lock_unset(&b->theaplock); if (tvp != 0 && tvp != b->batCacheid) BBPrelease(tvp); @@ -1166,10 +1173,57 @@ BUNappendmulti(BAT *b, const void *value b->tkey = count == 1; b->tnil = true; b->tnonil = false; + b->tunique_est = 1; } else { - b->tsorted = b->trevsorted = b->tkey = count == 1; + int c; b->tnil = b->tnonil = false; + switch (count) { + case 1: + b->tsorted = b->trevsorted = b->tkey = true; + b->tunique_est = 1; + break; + case 2: + if (b->tvheap) + c = ATOMcmp(b->ttype, + ((void **) values)[0], + ((void **) values)[1]); + else + c = ATOMcmp(b->ttype, + values, + (char *) values + b->twidth); + b->tsorted = c <= 0; + b->tnosorted = !b->tsorted; + b->trevsorted = c >= 0; + b->tnorevsorted = !b->trevsorted; + b->tkey = c != 0; + b->tnokey[0] = 0; + b->tnokey[1] = !b->tkey; + b->tunique_est = (double) (1 + b->tkey); + break; + default: + b->tsorted = b->trevsorted = b->tkey = false; + break; + } } + } else if (b->batCount == 1 && count == 1) { + BATiter bi = bat_iterator_nolock(b); + if (values != NULL) { + if (b->tvheap) + t = ((void **) values)[0]; + else + t = values; + } + int c = ATOMcmp(b->ttype, BUNtail(bi, 0), t); + b->tsorted = c <= 0; + b->tnosorted = !b->tsorted; + b->trevsorted = c >= 0; + b->tnorevsorted = !b->trevsorted; + b->tkey = c != 0; + b->tnokey[0] = 0; + b->tnokey[1] = !b->tkey; + b->tunique_est = (double) (1 + b->tkey); + b->tnil |= values == NULL; + b->tnonil = false; } else { b->tnil |= values == NULL; b->tnonil = false; diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c --- a/gdk/gdk_batop.c +++ b/gdk/gdk_batop.c @@ -596,6 +596,7 @@ append_msk_bat(BAT *b, BATiter *ni, stru /* boff < noff */ if (noff + cnt <= 32) { /* only need part of the first word of n */ + assert(cnt < 32); /* noff > 0, so cnt < 32 */ mask = (1U << cnt) - 1; *bp &= ~(mask << boff); *bp |= (*np & (mask << noff)) >> (noff - boff); diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c --- a/gdk/gdk_bbp.c +++ b/gdk/gdk_bbp.c @@ -634,6 +634,11 @@ heapinit(BAT *b, const char *buf, * in the structure pointed to by bn and extra information through the * other pointers; this function does not allocate any memory; return 0 * on end of file, 1 on success, and -1 on failure */ +/* set to true during initialization, else always false; if false, do + * not return any options (set pointer to NULL as if there aren't any); + * if true and there are options, return them in freshly allocated + * memory through *options */ +static bool return_options = false; int BBPreadBBPline(FILE *fp, unsigned bbpversion, int *lineno, BAT *bn, #ifdef GDKLIBRARY_HASHASH @@ -741,11 +746,20 @@ BBPreadBBPline(FILE *fp, unsigned bbpver } nread += n; - if (buf[nread] != '\n' && buf[nread] != ' ') { + if (nread >= (int) sizeof(buf) || (buf[nread] != '\n' && buf[nread] != ' ')) { TRC_CRITICAL(GDK, "invalid format for BBP.dir on line %d", *lineno); return -1; } - *options = (buf[nread] == ' ') ? buf + nread + 1 : NULL; + if (options) { + if (return_options && buf[nread] == ' ') { + if ((*options = GDKstrdup(buf + nread + 1)) == NULL) { + TRC_CRITICAL(GDK, "GDKstrdup failed\n"); + return -1; + } + } else { + *options = NULL; + } + } return 1; } @@ -762,6 +776,7 @@ BBPreadEntries(FILE *fp, unsigned bbpver #endif /* read the BBP.dir and insert the BATs into the BBP */ + return_options = true; for (;;) { BAT b; _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org