Changeset: 1d6eca5e0fca for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1d6eca5e0fca Added Files: sql/test/BugTracker-2017/Tests/simplify_math.Bug-6324.sql sql/test/BugTracker-2017/Tests/simplify_math.Bug-6324.stable.err sql/test/BugTracker-2017/Tests/simplify_math.Bug-6324.stable.out Modified Files: clients/odbc/driver/SQLTables.c gdk/gdk_atoms.c gdk/gdk_bat.c gdk/gdk_bbp.c gdk/gdk_heap.c gdk/gdk_utils.c monetdb5/modules/kernel/status.c monetdb5/modules/mal/bbp.c monetdb5/modules/mal/clients.c monetdb5/modules/mal/inspect.c monetdb5/modules/mal/mdb.c sql/server/rel_optimizer.c sql/test/BugTracker-2017/Tests/All tools/merovingian/daemon/controlrunner.c Branch: default Log Message:
Merge with Jul2017 branch. diffs (truncated from 648 to 300 lines): diff --git a/clients/odbc/driver/SQLTables.c b/clients/odbc/driver/SQLTables.c --- a/clients/odbc/driver/SQLTables.c +++ b/clients/odbc/driver/SQLTables.c @@ -224,7 +224,7 @@ MNDBTables(ODBCStmt *stmt, } /* construct the query now */ - query = (char *) malloc(1200 + (cat ? strlen(cat) : 0) + (sch ? strlen(sch) : 0) + (tab ? strlen(tab) : 0) + ((NameLength4 + 1) / 5) * 67); + query = (char *) malloc(2000 + (cat ? strlen(cat) : 0) + (sch ? strlen(sch) : 0) + (tab ? strlen(tab) : 0) + ((NameLength4 + 1) / 5) * 67); if (query == NULL) goto nomem; query_end = query; @@ -295,7 +295,7 @@ MNDBTables(ODBCStmt *stmt, "sys.env() e " "where s.id = t.schema_id and " "e.name = 'gdk_dbname'"); - assert(strlen(query) < 1100); + assert(strlen(query) < 1900); query_end += strlen(query_end); /* dependent on the input parameter values we must add a diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c --- a/gdk/gdk_atoms.c +++ b/gdk/gdk_atoms.c @@ -559,6 +559,84 @@ batToStr(char **dst, int *len, const bat * incorrect syntax (not a number) result in the function returning 0 * and setting the destination to nil. */ +struct maxdiv { + /* if we want to multiply a value with scale, the value must + * be no larger than maxval for there to not be overflow */ +#ifdef HAVE_HGE + hge scale, maxval; +#else + lng scale, maxval; +#endif +}; +static const struct maxdiv maxdiv[] = { +#ifdef HAVE_HGE + /* maximum hge value: 170141183460469231731687303715884105727 (2**127-1) + * GCC doesn't currently support integer constants that don't + * fit in 8 bytes, so we split large values up*/ + {(hge) LL_CONSTANT(1), (hge) LL_CONSTANT(17014118346046923173U) * LL_CONSTANT(10000000000000000000U)+ (hge) LL_CONSTANT(1687303715884105727)}, + {(hge) LL_CONSTANT(10), (hge) LL_CONSTANT(17014118346046923173U) * LL_CONSTANT(1000000000000000000) + (hge) LL_CONSTANT(168730371588410572)}, + {(hge) LL_CONSTANT(100), (hge) LL_CONSTANT(17014118346046923173U) * LL_CONSTANT(100000000000000000) + (hge) LL_CONSTANT(16873037158841057)}, + {(hge) LL_CONSTANT(1000), (hge) LL_CONSTANT(17014118346046923173U) * LL_CONSTANT(10000000000000000) + (hge) LL_CONSTANT(1687303715884105)}, + {(hge) LL_CONSTANT(10000), (hge) LL_CONSTANT(17014118346046923173U) * LL_CONSTANT(1000000000000000) + (hge) LL_CONSTANT(168730371588410)}, + {(hge) LL_CONSTANT(100000), (hge) LL_CONSTANT(17014118346046923173U) * LL_CONSTANT(100000000000000) + (hge) LL_CONSTANT(16873037158841)}, + {(hge) LL_CONSTANT(1000000), (hge) LL_CONSTANT(17014118346046923173U) * LL_CONSTANT(10000000000000) + (hge) LL_CONSTANT(1687303715884)}, + {(hge) LL_CONSTANT(10000000), (hge) LL_CONSTANT(17014118346046923173U) * LL_CONSTANT(1000000000000) + (hge) LL_CONSTANT(168730371588)}, + {(hge) LL_CONSTANT(100000000), (hge) LL_CONSTANT(17014118346046923173U) * LL_CONSTANT(100000000000) + (hge) LL_CONSTANT(16873037158)}, + {(hge) LL_CONSTANT(1000000000), (hge) LL_CONSTANT(17014118346046923173U) * LL_CONSTANT(10000000000) + (hge) LL_CONSTANT(1687303715)}, + {(hge) LL_CONSTANT(10000000000), (hge) LL_CONSTANT(17014118346046923173U) * LL_CONSTANT(1000000000) + (hge) LL_CONSTANT(168730371)}, + {(hge) LL_CONSTANT(100000000000), (hge) LL_CONSTANT(17014118346046923173U) * LL_CONSTANT(100000000) + (hge) LL_CONSTANT(16873037)}, + {(hge) LL_CONSTANT(1000000000000), (hge) LL_CONSTANT(17014118346046923173U) * LL_CONSTANT(10000000) + (hge) LL_CONSTANT(1687303)}, + {(hge) LL_CONSTANT(10000000000000), (hge) LL_CONSTANT(17014118346046923173U) * LL_CONSTANT(1000000) + (hge) LL_CONSTANT(168730)}, + {(hge) LL_CONSTANT(100000000000000), (hge) LL_CONSTANT(17014118346046923173U) * LL_CONSTANT(100000) + (hge) LL_CONSTANT(16873)}, + {(hge) LL_CONSTANT(1000000000000000), (hge) LL_CONSTANT(17014118346046923173U) * LL_CONSTANT(10000) + (hge) LL_CONSTANT(1687)}, + {(hge) LL_CONSTANT(10000000000000000), (hge) LL_CONSTANT(17014118346046923173U) * LL_CONSTANT(1000) + (hge) LL_CONSTANT(168)}, + {(hge) LL_CONSTANT(100000000000000000), (hge) LL_CONSTANT(17014118346046923173U) * LL_CONSTANT(100) + (hge) LL_CONSTANT(16)}, + {(hge) LL_CONSTANT(1000000000000000000), (hge) LL_CONSTANT(17014118346046923173U) * LL_CONSTANT(10) + (hge) LL_CONSTANT(1)}, + {(hge) LL_CONSTANT(10000000000000000000U) * LL_CONSTANT(1), (hge) LL_CONSTANT(17014118346046923173U)}, + {(hge) LL_CONSTANT(10000000000000000000U) * LL_CONSTANT(10), (hge) LL_CONSTANT(1701411834604692317)}, + {(hge) LL_CONSTANT(10000000000000000000U) * LL_CONSTANT(100), (hge) LL_CONSTANT(170141183460469231)}, + {(hge) LL_CONSTANT(10000000000000000000U) * LL_CONSTANT(1000), (hge) LL_CONSTANT(17014118346046923)}, + {(hge) LL_CONSTANT(10000000000000000000U) * LL_CONSTANT(10000), (hge) LL_CONSTANT(1701411834604692)}, + {(hge) LL_CONSTANT(10000000000000000000U) * LL_CONSTANT(100000), (hge) LL_CONSTANT(170141183460469)}, + {(hge) LL_CONSTANT(10000000000000000000U) * LL_CONSTANT(1000000), (hge) LL_CONSTANT(17014118346046)}, + {(hge) LL_CONSTANT(10000000000000000000U) * LL_CONSTANT(10000000), (hge) LL_CONSTANT(1701411834604)}, + {(hge) LL_CONSTANT(10000000000000000000U) * LL_CONSTANT(100000000), (hge) LL_CONSTANT(170141183460)}, + {(hge) LL_CONSTANT(10000000000000000000U) * LL_CONSTANT(1000000000), (hge) LL_CONSTANT(17014118346)}, + {(hge) LL_CONSTANT(10000000000000000000U) * LL_CONSTANT(10000000000), (hge) LL_CONSTANT(1701411834)}, + {(hge) LL_CONSTANT(10000000000000000000U) * LL_CONSTANT(100000000000), (hge) LL_CONSTANT(170141183)}, + {(hge) LL_CONSTANT(10000000000000000000U) * LL_CONSTANT(1000000000000), (hge) LL_CONSTANT(17014118)}, + {(hge) LL_CONSTANT(10000000000000000000U) * LL_CONSTANT(10000000000000), (hge) LL_CONSTANT(1701411)}, + {(hge) LL_CONSTANT(10000000000000000000U) * LL_CONSTANT(100000000000000), (hge) LL_CONSTANT(170141)}, + {(hge) LL_CONSTANT(10000000000000000000U) * LL_CONSTANT(1000000000000000), (hge) LL_CONSTANT(17014)}, + {(hge) LL_CONSTANT(10000000000000000000U) * LL_CONSTANT(10000000000000000), (hge) LL_CONSTANT(1701)}, + {(hge) LL_CONSTANT(10000000000000000000U) * LL_CONSTANT(100000000000000000), (hge) LL_CONSTANT(170)}, + {(hge) LL_CONSTANT(10000000000000000000U) * LL_CONSTANT(1000000000000000000), (hge) LL_CONSTANT(17)}, + {(hge) LL_CONSTANT(10000000000000000000U) * LL_CONSTANT(10000000000000000000U),(hge) LL_CONSTANT(1)}, +#else + /* maximum lng value: 9223372036854775807 (2**63-1) */ + {LL_CONSTANT(1), LL_CONSTANT(9223372036854775807)}, + {LL_CONSTANT(10), LL_CONSTANT(922337203685477580)}, + {LL_CONSTANT(100), LL_CONSTANT(92233720368547758)}, + {LL_CONSTANT(1000), LL_CONSTANT(9223372036854775)}, + {LL_CONSTANT(10000), LL_CONSTANT(922337203685477)}, + {LL_CONSTANT(100000), LL_CONSTANT(92233720368547)}, + {LL_CONSTANT(1000000), LL_CONSTANT(9223372036854)}, + {LL_CONSTANT(10000000), LL_CONSTANT(922337203685)}, + {LL_CONSTANT(100000000), LL_CONSTANT(92233720368)}, + {LL_CONSTANT(1000000000), LL_CONSTANT(9223372036)}, + {LL_CONSTANT(10000000000), LL_CONSTANT(922337203)}, + {LL_CONSTANT(100000000000), LL_CONSTANT(92233720)}, + {LL_CONSTANT(1000000000000), LL_CONSTANT(9223372)}, + {LL_CONSTANT(10000000000000), LL_CONSTANT(922337)}, + {LL_CONSTANT(100000000000000), LL_CONSTANT(92233)}, + {LL_CONSTANT(1000000000000000), LL_CONSTANT(9223)}, + {LL_CONSTANT(10000000000000000), LL_CONSTANT(922)}, + {LL_CONSTANT(100000000000000000), LL_CONSTANT(92)}, + {LL_CONSTANT(1000000000000000000), LL_CONSTANT(9)}, +#endif +}; +static const int maxmod10 = 7; /* (int) (maxdiv[0].maxval % 10) */ + static int numFromStr(const char *src, int *len, void **dst, int tp) { @@ -566,16 +644,19 @@ numFromStr(const char *src, int *len, vo int sz = ATOMsize(tp); #ifdef HAVE_HGE hge base = 0; - hge expbase = -1; - const hge maxdiv10 = GDK_hge_max / 10; #else lng base = 0; - lng expbase = -1; - const lng maxdiv10 = LL_CONSTANT(922337203685477580); /*7*/ #endif - const int maxmod10 = 7; /* max value % 10 */ int sign = 1; + /* a valid number has the following syntax: + * [-+]?[0-9]+([eE][0-9]+)?(LL)? -- PCRE syntax, or in other words + * optional sign, one or more digits, optional exponent, optional LL + * the exponent has the following syntax: + * lower or upper case letter E, one or more digits + * embedded spaces are not allowed + * the optional LL at the end are only allowed for lng and hge + * values */ atommem(void, sz); while (GDKisspace(*p)) p++; @@ -599,50 +680,45 @@ numFromStr(const char *src, int *len, vo } if (!num10(*p)) { /* still not a number */ - memcpy(*dst, ATOMnilptr(tp), sz); - return 0; + goto bailout; } } do { - if (base > maxdiv10 || - (base == maxdiv10 && base10(*p) > maxmod10)) { + int dig = base10(*p); + if (base > maxdiv[1].maxval || + (base == maxdiv[1].maxval && dig > maxmod10)) { /* overflow */ - memcpy(*dst, ATOMnilptr(tp), sz); - return 0; + goto bailout; } - base = 10 * base + base10(*p); + base = 10 * base + dig; p++; - /* Special case: xEy = x*10^y handling part 1 */ - if (*p == 'E' || *p == 'e') { - // if there is a second E in the string we give up - if (expbase > -1) { - memcpy(*dst, ATOMnilptr(tp), sz); - return 0; + } while (num10(*p)); + if ((*p == 'e' || *p == 'E') && num10(p[1])) { + p++; + if (base == 0) { + /* if base is 0, any exponent will do, the + * result is still 0 */ + while (num10(*p)) + p++; + } else { + int exp = 0; + do { + /* this calculation cannot overflow */ + exp = exp * 10 + base10(*p); + if (exp >= (int) (sizeof(maxdiv) / sizeof(maxdiv[0]))) { + /* overflow */ + goto bailout; + } + p++; + } while (num10(*p)); + if (base > maxdiv[exp].maxval) { + /* overflow */ + goto bailout; } - expbase = base; - base = 0; - p++; + base *= maxdiv[exp].scale; } - } while (num10(*p)); - /* Special case: xEy = x*10^y handling part 2 */ - if (expbase > -1) { -#ifdef HAVE_HGE - hge res = expbase; -#else - lng res = expbase; -#endif - while (base > 0) { - if (res > maxdiv10) { - memcpy(*dst, ATOMnilptr(tp), sz); - return 0; - } - res *= 10L; - base--; - } - base = res; } base *= sign; - switch (sz) { case 1: { bte **dstbte = (bte **) dst; @@ -697,6 +773,10 @@ numFromStr(const char *src, int *len, vo while (GDKisspace(*p)) p++; return (int) (p - src); + + bailout: + memcpy(*dst, ATOMnilptr(tp), sz); + return 0; } int diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c --- a/gdk/gdk_bat.c +++ b/gdk/gdk_bat.c @@ -508,22 +508,19 @@ BATclear(BAT *b, int force) /* we must dispose of all inserted atoms */ if (force && BATatoms[b->ttype].atomDel == NULL) { - Heap th; - + assert(b->tvheap == NULL || b->tvheap->parentid == b->batCacheid); /* no stable elements: we do a quick heap clean */ /* need to clean heap which keeps data even though the BUNs got removed. This means reinitialize when free > 0 */ - memset(&th, 0, sizeof(th)); - if (b->tvheap) { + if (b->tvheap && b->tvheap->free > 0) { + Heap th; + + memset(&th, 0, sizeof(th)); th.farmid = b->tvheap->farmid; - if (b->tvheap->free > 0 && - ATOMheap(b->ttype, &th, 0) != GDK_SUCCEED) + if (ATOMheap(b->ttype, &th, 0) != GDK_SUCCEED) return GDK_FAIL; - } - assert(b->tvheap == NULL || b->tvheap->parentid == b->batCacheid); - if (b->tvheap && b->tvheap->free > 0) { th.parentid = b->tvheap->parentid; HEAPfree(b->tvheap, 0); *b->tvheap = th; @@ -537,7 +534,7 @@ BATclear(BAT *b, int force) if (tatmdel) { BATiter bi = bat_iterator(b); - for(p = b->batInserted, q = BUNlast(b); p < q; p++) + for (p = b->batInserted, q = BUNlast(b); p < q; p++) (*tatmdel)(b->tvheap, (var_t*) BUNtloc(bi,p)); } } diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c --- a/gdk/gdk_bbp.c +++ b/gdk/gdk_bbp.c @@ -1466,7 +1466,7 @@ BBPexit(void) skipped = 0; for (i = 0; i < (bat) ATOMIC_GET(BBPsize, BBPsizeLock); i++) { if (BBPvalid(i)) { - BAT *b = BBP_cache(i); + BAT *b = BBP_desc(i); if (b) { if (b->batSharecnt > 0) { @@ -1483,11 +1483,11 @@ BBPexit(void) bat tp = VIEWtparent(b); bat vtp = VIEWvtparent(b); if (tp) { - BBP_cache(tp)->batSharecnt--; + BBP_desc(tp)->batSharecnt--; --BBP_lrefs(tp); } if (vtp) { - BBP_cache(vtp)->batSharecnt--; + BBP_desc(vtp)->batSharecnt--; --BBP_lrefs(vtp); } VIEWdestroy(b); @@ -1811,42 +1811,57 @@ BBPdump(void) continue; fprintf(stderr, "# %d[%s]: nme='%s' refs=%d lrefs=%d " - "status=%d count=" BUNFMT " " - "Theap=[" SZFMT "," SZFMT "] " - "Tvheap=[" SZFMT "," SZFMT "] " - "Thash=[" SZFMT "," SZFMT "]\n", _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list