Changeset: a3272f65e2b7 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a3272f65e2b7
Modified Files:
        common/stream/stream.c
        monetdb5/extras/rapi/rapi.c
        monetdb5/mal/mal_listing.c
        monetdb5/mal/mal_type.c
        monetdb5/modules/atoms/inet.c
        monetdb5/modules/atoms/json.c
        monetdb5/modules/kernel/algebra.c
        monetdb5/modules/mal/clients.c
        monetdb5/modules/mal/sysmon.c
        monetdb5/modules/mal/tablet.c
        sql/backends/monet5/generator/generator.c
        sql/backends/monet5/vaults/shp/shp.c
        sql/test/pg_regress/Tests/float8.stable.out
Branch: Dec2016
Log Message:

Various bug fixes.


diffs (truncated from 426 to 300 lines):

diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -2965,7 +2965,11 @@ file_rastream(FILE *fp, const char *name
                        s->isutf8 = 1;
                        return s;
                }
-               file_fsetpos(s, pos);
+               if (file_fsetpos(s, pos) < 0) {
+                       /* unlikely: we couldn't seek the file back */
+                       destroy(s);
+                       return NULL;
+               }
        }
 #ifdef _MSC_VER
        if (_fileno(fp) == 0 && _isatty(0)) {
diff --git a/monetdb5/extras/rapi/rapi.c b/monetdb5/extras/rapi/rapi.c
--- a/monetdb5/extras/rapi/rapi.c
+++ b/monetdb5/extras/rapi/rapi.c
@@ -479,10 +479,12 @@ void* RAPIloopback(void *query) {
                        retlist = PROTECT(allocVector(VECSXP, ncols));
                        names = PROTECT(NEW_STRING(ncols));
                        for (i = 0; i < ncols; i++) {
-                               if (!(varvalue = 
bat_to_sexp(BATdescriptor(output->cols[i].b)))) {
+                               BAT *b = BATdescriptor(output->cols[i].b);
+                               if (b == NULL || !(varvalue = bat_to_sexp(b))) {
                                        UNPROTECT(i + 3);
                                        return ScalarString(RSTR("Conversion 
error"));
                                }
+                               BBPunfix(b->batCacheid);
                                SET_STRING_ELT(names, i, 
RSTR(output->cols[i].name));
                                SET_VECTOR_ELT(retlist, i, varvalue);
                        }
diff --git a/monetdb5/mal/mal_listing.c b/monetdb5/mal/mal_listing.c
--- a/monetdb5/mal/mal_listing.c
+++ b/monetdb5/mal/mal_listing.c
@@ -70,14 +70,20 @@ renderTerm(MalBlkPtr mb, MalStkPtr stk, 
                } else if( stk)
                        val = &stk->stk[varid];
 
-               VALformat(&cv, val);
-               if (len + strlen(cv) >= maxlen)
-                       buf= GDKrealloc(buf, maxlen =len + strlen(cv) + BUFSIZ);
-
-               if( buf == 0){
+               if (VALformat(&cv, val) <= 0) {
+                       GDKfree(buf);
                        GDKerror("renderTerm:Failed to allocate");
                        return NULL;
                }
+               if (len + strlen(cv) >= maxlen) {
+                       char *nbuf = GDKrealloc(buf, maxlen =len + strlen(cv) + 
BUFSIZ);
+                       if (nbuf == NULL) {
+                               GDKfree(buf);
+                               GDKerror("renderTerm:Failed to allocate");
+                               return NULL;
+                       }
+                       buf = nbuf;
+               }
 
                if( strcmp(cv,"nil") == 0){
                        strcat(buf+len,cv);
@@ -93,7 +99,7 @@ renderTerm(MalBlkPtr mb, MalStkPtr stk, 
                        }
                        strcat(buf+len,cv);
                        len += strlen(buf+len);
-                       if( cv) GDKfree(cv);
+                       GDKfree(cv);
 
                        if( closequote ){
                                strcat(buf+len,"\"");
@@ -116,6 +122,11 @@ renderTerm(MalBlkPtr mb, MalStkPtr stk, 
                strcat(buf + len,":");
                len++;
                tpe = getTypeName(getVarType(mb, varid));
+               if (tpe == NULL) {
+                       GDKfree(buf);
+                       GDKerror("renderTerm:Failed to allocate");
+                       return NULL;
+               }
                len += snprintf(buf+len,maxlen-len,"%s",tpe);
                GDKfree(tpe);
        }
diff --git a/monetdb5/mal/mal_type.c b/monetdb5/mal/mal_type.c
--- a/monetdb5/mal/mal_type.c
+++ b/monetdb5/mal/mal_type.c
@@ -34,30 +34,24 @@
 str
 getTypeName(malType tpe)
 {
-       char buf[PATHLENGTH], *s;
-       size_t l = PATHLENGTH;
+       char buf[PATHLENGTH];
        int k;
 
        if (tpe == TYPE_any)
                return GDKstrdup("any");
        if (isaBatType(tpe)) {
-               snprintf(buf, l, "bat[");
-               l -= strlen(buf);
-               s = buf + strlen(buf);
                k = getTypeIndex(tpe);
                if (k)
-                       snprintf(s, l, ":any%c%d]",TMPMARKER,  k);
+                       snprintf(buf, sizeof(buf), "bat[:any%c%d]",TMPMARKER,  
k);
                else if (getBatType(tpe) == TYPE_any)
-                       snprintf(s, l, ":any]");
+                       snprintf(buf, sizeof(buf), "bat[:any]");
                else
-                       snprintf(s, l, ":%s]", ATOMname(getBatType(tpe)));
+                       snprintf(buf, sizeof(buf), "bat[:%s]", 
ATOMname(getBatType(tpe)));
                return GDKstrdup(buf);
        }
        if (isAnyExpression(tpe)) {
-               strncpy(buf, "any", 4);
-               if (isAnyExpression(tpe))
-                       snprintf(buf + 3, PATHLENGTH - 3, "%c%d",
-                                       TMPMARKER, getTypeIndex(tpe));
+               snprintf(buf, sizeof(buf), "any%c%d",
+                                TMPMARKER, getTypeIndex(tpe));
                return GDKstrdup(buf);
        }
        return GDKstrdup(ATOMname(tpe));
diff --git a/monetdb5/modules/atoms/inet.c b/monetdb5/modules/atoms/inet.c
--- a/monetdb5/modules/atoms/inet.c
+++ b/monetdb5/modules/atoms/inet.c
@@ -122,7 +122,8 @@ INETfromString(const char *src, int *len
                *retval = GDKzalloc(sizeof(inet));
                if( *retval == NULL){
                        GDKerror("INETfromString "MAL_MALLOC_FAIL);
-                       goto error;
+                       *len = 0;
+                       return 0;
                }
        } else {
                memset(*retval, 0, sizeof(inet));
diff --git a/monetdb5/modules/atoms/json.c b/monetdb5/modules/atoms/json.c
--- a/monetdb5/modules/atoms/json.c
+++ b/monetdb5/modules/atoms/json.c
@@ -1771,8 +1771,7 @@ JSONrenderarray(Client cntxt, MalBlkPtr 
        cnt = BATcount(bl[pci->retc + 1]);
        result = GDKmalloc(lim = BUFSIZ);
        if( result == NULL) {
-               JSONfreeArgumentlist(bl, pci);
-               throw(MAL,"json.renderArray",MAL_MALLOC_FAIL);
+               goto memfail;
        }
        result[0] = '[';
        result[1] = 0;
@@ -1789,6 +1788,7 @@ JSONrenderarray(Client cntxt, MalBlkPtr 
                        lim = cnt * l <= lim ? cnt * l : lim + BUFSIZ;
                result2 = GDKrealloc(result, lim);
                if (result2 == NULL) {
+                       GDKfree(row);
                        goto memfail;
                }
                result = result2;
diff --git a/monetdb5/modules/kernel/algebra.c 
b/monetdb5/modules/kernel/algebra.c
--- a/monetdb5/modules/kernel/algebra.c
+++ b/monetdb5/modules/kernel/algebra.c
@@ -950,12 +950,7 @@ doALGfetch(ptr ret, BAT *b, BUN pos)
                *(ptr*) ret = _dst;
        } else {
                int _s = ATOMsize(ATOMtype(b->ttype));
-               if (ATOMvarsized(b->ttype)) {
-                       ret = GDKmalloc(_s);
-                       if( ret == NULL)
-                               throw(MAL,"doAlgFetch",MAL_MALLOC_FAIL);
-                       memcpy(*(ptr*) ret, BUNtvar(bi, pos), _s);
-               } else if (b->ttype == TYPE_void) {
+               if (b->ttype == TYPE_void) {
                        *(oid*) ret = b->tseqbase;
                        if (b->tseqbase != oid_nil)
                                *(oid*)ret += pos;
diff --git a/monetdb5/modules/mal/clients.c b/monetdb5/modules/mal/clients.c
--- a/monetdb5/modules/mal/clients.c
+++ b/monetdb5/modules/mal/clients.c
@@ -601,7 +601,7 @@ CLTsessions(Client cntxt, MalBlkPtr mb, 
        last = COLnew(0, TYPE_timestamp, 0, TRANSIENT);
        qtimeout = COLnew(0, TYPE_lng, 0, TRANSIENT);
        active = COLnew(0, TYPE_bit, 0, TRANSIENT);
-       if ( user == NULL || login == NULL || stimeout == NULL || qtimeout == 
NULL || active == NULL){
+       if ( user == NULL || login == NULL || stimeout == NULL || last == NULL 
|| qtimeout == NULL || active == NULL){
                if ( user) BBPunfix(user->batCacheid);
                if ( login) BBPunfix(login->batCacheid);
                if ( stimeout) BBPunfix(stimeout->batCacheid);
diff --git a/monetdb5/modules/mal/sysmon.c b/monetdb5/modules/mal/sysmon.c
--- a/monetdb5/modules/mal/sysmon.c
+++ b/monetdb5/modules/mal/sysmon.c
@@ -45,7 +45,7 @@ SYSMONqueue(Client cntxt, MalBlkPtr mb, 
        activity = COLnew(0, TYPE_str, 256, TRANSIENT);
        oids = COLnew(0, TYPE_oid, 256, TRANSIENT);
        query = COLnew(0, TYPE_str, 256, TRANSIENT);
-       if ( tag == NULL || query == NULL || started == NULL || estimate == 
NULL || progress == NULL || activity == NULL || oids == NULL){
+       if ( tag == NULL || user == NULL || query == NULL || started == NULL || 
estimate == NULL || progress == NULL || activity == NULL || oids == NULL){
                if (tag) BBPunfix(tag->batCacheid);
                if (user) BBPunfix(user->batCacheid);
                if (query) BBPunfix(query->batCacheid);
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
@@ -354,12 +354,12 @@ output_line(char **buf, int *len, char *
                                }
                                if (fill + l + f->seplen >= *len) {
                                        /* extend the buffer */
-                                       *buf = GDKrealloc(*buf, fill + l + 
f->seplen + BUFSIZ);
-                                       if( buf == NULL)
-                                               return -1;
+                                       char *nbuf;
+                                       nbuf = GDKrealloc(*buf, fill + l + 
f->seplen + BUFSIZ);
+                                       if( nbuf == NULL)
+                                               return -1; /* *buf freed by 
caller */
+                                       *buf = nbuf;
                                        *len = fill + l + f->seplen + BUFSIZ;
-                                       if (*buf == NULL)
-                                               return -1;
                                }
                                strncpy(*buf + fill, p, l);
                                fill += l;
@@ -396,12 +396,12 @@ output_line_dense(char **buf, int *len, 
                        }
                        if (fill + l + f->seplen >= *len) {
                                /* extend the buffer */
-                               *buf = GDKrealloc(*buf, fill + l + f->seplen + 
BUFSIZ);
-                               if( buf == NULL)
-                                       return 0;
+                               char *nbuf;
+                               nbuf = GDKrealloc(*buf, fill + l + f->seplen + 
BUFSIZ);
+                               if( nbuf == NULL)
+                                       return -1;      /* *buf freed by caller 
*/
+                               *buf = nbuf;
                                *len = fill + l + f->seplen + BUFSIZ;
-                               if (*buf == NULL)
-                                       return -1;
                        }
                        strncpy(*buf + fill, p, l);
                        fill += l;
@@ -718,7 +718,7 @@ tablet_error(READERtask *task, lng row, 
                BUNappend(task->cntxt->error_input, fcn, FALSE);
                if (task->as->error == NULL && (msg == NULL || (task->as->error 
= GDKstrdup(msg)) == NULL))
                        task->as->error = createException(MAL, "sql.copy_from", 
MAL_MALLOC_FAIL);
-               if (row != lng_nil)
+               if (row != lng_nil && task->rowerror)
                        task->rowerror[row]++;
 #ifdef _DEBUG_TABLET_
                mnstr_printf(GDKout, "#tablet_error: " LLFMT ",%d:%s:%s\n",
diff --git a/sql/backends/monet5/generator/generator.c 
b/sql/backends/monet5/generator/generator.c
--- a/sql/backends/monet5/generator/generator.c
+++ b/sql/backends/monet5/generator/generator.c
@@ -829,11 +829,11 @@ str VLTgenerator_projection(Client cntxt
                s = f<l? (TPE) 1: (TPE)-1;\
        else s = * getArgReference_##TPE(stk, p, 3); \
        incr = s > 0;\
-       v = (TPE*) Tloc(bl,0);\
+       v = (TPE*) Tloc(b,0);\
        if ( s == 0 || (f> l && s>0) || (f<l && s < 0))\
                throw(MAL,"generator.join","Illegal range");\
        for( ; cnt >0; cnt--,o++,v++){\
-               w = (BUN) floor( (double)(ABS(*v -f)/ABS(s)));\
+               w = (BUN) (ABS(*v -f)/ABS(s));\
                if ( f + (TPE)(w * s) == *v ){\
                        *ol++ = (oid) w;\
                        *or++ = o;\
@@ -853,16 +853,30 @@ str VLTgenerator_join(Client cntxt, MalB
        (void) cntxt;
        // we assume at most one of the arguments to refer to the generator
        p = findGeneratorDefinition(mb,pci,pci->argv[2]);
+       q = findGeneratorDefinition(mb,pci,pci->argv[3]);
+
+       if (p == NULL && q == NULL) {
+               bit zero = 0;
+               return ALGsubjoin(getArgReference_bat(stk, pci, 0),
+                                 getArgReference_bat(stk, pci, 1),
+                                 getArgReference_bat(stk, pci, 2),
+                                 getArgReference_bat(stk, pci, 3),
+                                 NULL, /* left candidate */
+                                 NULL, /* right candidate */
+                                 &zero, /* nil_matches */
+                                 NULL); /* estimate */
+       }
+
        if( p == NULL){
                bl = BATdescriptor(*getArgReference_bat(stk,pci,2));
                if( bl == NULL)
                        throw(MAL,"generator.join",RUNTIME_OBJECT_MISSING);
        }
-       q = findGeneratorDefinition(mb,pci,pci->argv[3]);
        if ( q == NULL){
                br = BATdescriptor(*getArgReference_bat(stk,pci,3));
                if( br == NULL){
-                       BBPunfix(bl->batCacheid);
+                       if (bl)
+                               BBPunfix(bl->batCacheid);
                        throw(MAL,"generator.join",RUNTIME_OBJECT_MISSING);
                }
        }
@@ -900,26 +914,7 @@ str VLTgenerator_join(Client cntxt, MalB
 
        /* The actual join code for generators be injected here */
        switch(tpe){
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to