Changeset: d8a1fa629501 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d8a1fa629501 Modified Files: clients/mapiclient/mclient.c clients/mapiclient/mhelp.c clients/mapilib/mapi.c common/stream/stream.c gdk/gdk_aggr.c gdk/gdk_firstn.c gdk/gdk_logger.c gdk/gdk_orderidx.c gdk/gdk_storage.c gdk/gdk_utils.c geom/monetdb5/geomBulk.c monetdb5/mal/mal_authorize.c monetdb5/mal/mal_instruction.c monetdb5/mal/mal_interpreter.c monetdb5/mal/mal_module.c monetdb5/mal/mal_parser.c monetdb5/mal/mal_scenario.c monetdb5/mal/mal_session.c monetdb5/modules/atoms/json.c monetdb5/modules/atoms/str.c monetdb5/modules/atoms/uuid.c monetdb5/modules/mal/inspect.c monetdb5/modules/mal/mal_mapi.c monetdb5/modules/mal/mdb.c monetdb5/modules/mal/oltp.c monetdb5/optimizer/opt_evaluate.c monetdb5/optimizer/opt_json.c monetdb5/optimizer/opt_macro.c monetdb5/optimizer/opt_mergetable.c monetdb5/optimizer/opt_multiplex.c monetdb5/optimizer/opt_oltp.c monetdb5/optimizer/opt_support.c sql/backends/monet5/generator/generator.c sql/backends/monet5/rel_bin.c Branch: Jul2017 Log Message:
Merged changes diffs (truncated from 927 to 300 lines): diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c --- a/clients/mapiclient/mclient.c +++ b/clients/mapiclient/mclient.c @@ -2283,9 +2283,10 @@ doFile(Mapi mid, stream *fp, int useinse #ifdef HAVE_LIBREADLINE struct myread_t rl; #endif + int fd; (void) save_history; /* not used if no readline */ - if (isatty(getFileNo(fp)) /* fails if not a FILE* */ + if ((fd = getFileNo(fp)) >= 0 && isatty(fd) #ifdef WIN32 /* isatty may not give expected result */ && formatter != TESTformatter #endif @@ -2334,11 +2335,8 @@ doFile(Mapi mid, stream *fp, int useinse for (;;) { ssize_t l; l = mnstr_readline(fp, buf + length, bufsiz - length); - if (l <= 0) { - if (length == 0) - length = l; + if (l <= 0) break; - } if (!seen_null_byte && strlen(buf + length) < (size_t) l) { fprintf(stderr, "NULL byte in input on line %d of input\n", lineno); seen_null_byte = 1; @@ -2357,7 +2355,7 @@ doFile(Mapi mid, stream *fp, int useinse lineno++; if (seen_null_byte) continue; - if (length <= 0) { + if (length == 0) { /* end of file */ if (hdl == NULL) { /* nothing more to do */ @@ -2366,7 +2364,6 @@ doFile(Mapi mid, stream *fp, int useinse } /* hdl != NULL, we should finish the current query */ - length = 0; } if (hdl == NULL && length > 0 && interactive) { /* test for special commands */ diff --git a/clients/mapiclient/mhelp.c b/clients/mapiclient/mhelp.c --- a/clients/mapiclient/mhelp.c +++ b/clients/mapiclient/mhelp.c @@ -823,7 +823,7 @@ sql_word(const char *word, size_t maxlen void sql_help(char *pattern, stream *toConsole, int pagewidth) { - size_t maxlen = 0, len; + size_t maxlen = 1, len; int i, step, ncolumns, total = 0; if (*pattern == '\\') diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c --- a/clients/mapilib/mapi.c +++ b/clients/mapilib/mapi.c @@ -1888,7 +1888,7 @@ parse_uri_query(Mapi mid, char *uri) char *val; /* just don't care where it is, assume it all starts from '?' */ - if ((uri = strchr(uri, '?')) == NULL) + if (uri == NULL || (uri = strchr(uri, '?')) == NULL) return; *uri++ = '\0'; /* skip '?' */ @@ -2446,7 +2446,7 @@ mapi_reconnect(Mapi mid) if (s == INVALID_SOCKET) continue; #ifdef HAVE_FCNTL - fcntl(s, F_SETFD, FD_CLOEXEC); + (void) fcntl(s, F_SETFD, FD_CLOEXEC); #endif if (connect(s, rp->ai_addr, (socklen_t) rp->ai_addrlen) != SOCKET_ERROR) break; /* success */ @@ -3366,7 +3366,18 @@ mapi_param_store(MapiHdl hdl) buf[0] = *(char *) src; buf[1] = 0; val = mapi_quote(buf, 1); - checkSpace(strlen(val) + 3); + /* note: k==strlen(hdl->query) */ + if (k + strlen(val) + 3 >= lim) { + char *q = hdl->query; + lim = k + strlen(val) + 3 + MAPIBLKSIZE; + hdl->query = realloc(hdl->query, lim); + if (hdl->query == NULL) { + free(q); + free(val); + return; + } + hdl->query = q; + } sprintf(hdl->query + k, "'%s'", val); free(val); break; diff --git a/common/stream/stream.c b/common/stream/stream.c --- a/common/stream/stream.c +++ b/common/stream/stream.c @@ -2598,7 +2598,7 @@ udp_socket(udp_stream *udp, const char * if (udp->s == INVALID_SOCKET) continue; #ifdef HAVE_FCNTL - fcntl(udp->s, F_SETFD, FD_CLOEXEC); + (void) fcntl(udp->s, F_SETFD, FD_CLOEXEC); #endif if (!write && bind(udp->s, rp->ai_addr, @@ -4128,13 +4128,13 @@ bs2_create(stream *s, size_t bufsiz, com ns->compbufsiz = compress_bound; ns->compbuf = malloc(ns->compbufsiz); if (!ns->compbuf) { + free(ns->buf); free(ns); - free(ns->buf); return NULL; } } else if (compress_bound < 0) { + free(ns->buf); free(ns); - free(ns->buf); return NULL; } return ns; diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c --- a/gdk/gdk_aggr.c +++ b/gdk/gdk_aggr.c @@ -2290,7 +2290,6 @@ BATminmax(BAT *b, void *aggr, oid pos; const void *res; int s; - int needdecref = 0; BATiter bi; if ((VIEWtparent(b) == 0 || @@ -2333,8 +2332,6 @@ BATminmax(BAT *b, void *aggr, } if (aggr != NULL) /* else: malloc error */ memcpy(aggr, res, s); - if (needdecref) - BBPunfix(b->batCacheid); return aggr; } diff --git a/gdk/gdk_firstn.c b/gdk/gdk_firstn.c --- a/gdk/gdk_firstn.c +++ b/gdk/gdk_firstn.c @@ -698,13 +698,10 @@ BATfirstn_grouped_with_groups(BAT **topn if (rc != GDK_SUCCEED) return GDK_FAIL; BBPunfix(bn7->batCacheid); - if (s) { - bn = BATproject(bn8, s); - BBPunfix(bn8->batCacheid); - if (bn == NULL) - return GDK_FAIL; - } else - bn = bn8; + bn = BATproject(bn8, s); + BBPunfix(bn8->batCacheid); + if (bn == NULL) + return GDK_FAIL; } else { bn = BATfirstn_unique_with_groups(b, s, g, n, asc, &last, &lastg); if (bn == NULL) diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c --- a/gdk/gdk_logger.c +++ b/gdk/gdk_logger.c @@ -945,6 +945,7 @@ logger_readlog(logger *lg, char *filenam time_t t0, t1; struct stat sb; int dbg = GDKdebug; + int fd; GDKdebug &= ~(CHECKMASK|PROPMASK); @@ -961,7 +962,7 @@ logger_readlog(logger *lg, char *filenam GDKdebug = dbg; return GDK_SUCCEED; } - if (fstat(getFileNo(lg->log), &sb) < 0) { + if ((fd = getFileNo(lg->log)) < 0 || fstat(fd, &sb) < 0) { fprintf(stderr, "!ERROR: logger_readlog: fstat on opened file %s failed\n", filename); mnstr_destroy(lg->log); lg->log = NULL; diff --git a/gdk/gdk_orderidx.c b/gdk/gdk_orderidx.c --- a/gdk/gdk_orderidx.c +++ b/gdk/gdk_orderidx.c @@ -62,6 +62,8 @@ BATcheckorderidx(BAT *b) int ret; lng t = 0; + if (b == NULL) + return 0; assert(b->batCacheid > 0); ALGODEBUG t = GDKusec(); MT_lock_set(&GDKhashLock(b->batCacheid)); diff --git a/gdk/gdk_storage.c b/gdk/gdk_storage.c --- a/gdk/gdk_storage.c +++ b/gdk/gdk_storage.c @@ -323,6 +323,10 @@ GDKextendf(int fd, size_t size, const ch int rt = 0; int t0 = 0; +#ifdef STATIC_CODE_ANALYSIS + if (fd < 0) /* in real life, if fd < 0, fstat will fail */ + return GDK_FAIL; +#endif if (fstat(fd, &stb) < 0) { /* shouldn't happen */ GDKsyserror("GDKextendf: fstat unexpectedly failed\n"); diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c --- a/gdk/gdk_utils.c +++ b/gdk/gdk_utils.c @@ -1823,8 +1823,10 @@ char * GDKstrndup(const char *s, size_t size) { char *p = malloc(size + 1); - if (p == NULL) + if (p == NULL) { GDKerror("GDKstrdup failed for %s\n", s); + return NULL; + } memcpy(p, s, size); p[size] = 0; return p; diff --git a/geom/monetdb5/geomBulk.c b/geom/monetdb5/geomBulk.c --- a/geom/monetdb5/geomBulk.c +++ b/geom/monetdb5/geomBulk.c @@ -1347,7 +1347,9 @@ wkbMakeLine_bat(bat *outBAT_id, bat *aBA BUN i; //get the BATs - if ((aBAT = BATdescriptor(*aBAT_id)) == NULL || (bBAT = BATdescriptor(*bBAT_id)) == NULL) { + aBAT = BATdescriptor(*aBAT_id); + bBAT = BATdescriptor(*bBAT_id); + if (aBAT == NULL || bBAT == NULL) { if (aBAT) BBPunfix(aBAT->batCacheid); if (bBAT) @@ -1410,7 +1412,9 @@ wkbUnion_bat(bat *outBAT_id, bat *aBAT_i BUN i; //get the BATs - if ((aBAT = BATdescriptor(*aBAT_id)) == NULL || (bBAT = BATdescriptor(*bBAT_id)) == NULL) { + aBAT = BATdescriptor(*aBAT_id); + bBAT = BATdescriptor(*bBAT_id); + if (aBAT == NULL || bBAT == NULL) { if (aBAT) BBPunfix(aBAT->batCacheid); if (bBAT) diff --git a/monetdb5/mal/mal_authorize.c b/monetdb5/mal/mal_authorize.c --- a/monetdb5/mal/mal_authorize.c +++ b/monetdb5/mal/mal_authorize.c @@ -119,13 +119,12 @@ AUTHrequireAdminOrUser(Client cntxt, con return(MAL_SUCCEED); rethrow("requireAdminOrUser", tmp, AUTHresolveUser(&user, id)); - if (username == NULL || strcmp(username, user) != 0) { - GDKfree(user); - throw(INVCRED, "requireAdminOrUser", INVCRED_ACCESS_DENIED " '%s'", user); - } + if (username == NULL || strcmp(username, user) != 0) + tmp = createException(INVCRED, "requireAdminOrUser", + INVCRED_ACCESS_DENIED " '%s'", user); + GDKfree(user); - - return(MAL_SUCCEED); + return tmp; } static void 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 @@ -790,8 +790,6 @@ clearVariable(MalBlkPtr mb, int varid) VarPtr v; v = getVar(mb, varid); - if (v == 0) - return; if (isVarConstant(mb, varid) || isVarDisabled(mb, varid)) VALclear(&v->value); v->type = 0; diff --git a/monetdb5/mal/mal_interpreter.c b/monetdb5/mal/mal_interpreter.c --- a/monetdb5/mal/mal_interpreter.c +++ b/monetdb5/mal/mal_interpreter.c @@ -599,9 +599,10 @@ str runMALsequence(Client cntxt, MalBlkP for (i = 0; i < pci->argc; i++) { int a = getArg(pci, i); - garbage[i] = -1; if (stk->stk[a].vtype == TYPE_bat && getEndScope(mb, a) == stkpc && isNotUsedIn(pci, i + 1, a)) garbage[i] = a; + else + garbage[i] = -1; } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list