Changeset: 89332a1775b1 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/89332a1775b1
Modified Files:
        monetdb5/mal/mal_authorize.c
        monetdb5/mal/mal_profiler.c
        monetdb5/modules/atoms/url.c
        monetdb5/modules/atoms/uuid.c
        monetdb5/modules/mal/clients.c
        monetdb5/modules/mal/mkey.c
Branch: Sep2022
Log Message:

More fixes.


diffs (218 lines):

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
@@ -351,7 +351,7 @@ AUTHgetUsername(str *username, Client cn
                *username = GDKstrdup(cntxt->username);
                return(MAL_SUCCEED);
        }
-       if (authCallbackCntx.get_user_name && cntxt) {
+       if (authCallbackCntx.get_user_name) {
                if ((*username = authCallbackCntx.get_user_name(cntxt)) == 
NULL) {
                        throw(MAL, "getUsername", INVCRED_WRONG_ID);
                }
diff --git a/monetdb5/mal/mal_profiler.c b/monetdb5/mal/mal_profiler.c
--- a/monetdb5/mal/mal_profiler.c
+++ b/monetdb5/mal/mal_profiler.c
@@ -135,33 +135,35 @@ logadd(struct logbuf *logbuf, const char
                va_end(va2);
                return false;
        }
-       if (logbuf->loglen + (size_t) tmp_len >= logbuf->logcap) {
-               if ((size_t) tmp_len >= logbuf->logcap) {
-                       /* includes first time when logbuffer == NULL and 
logcap = 0 */
-                       char *alloc_buff;
-                       if (logbuf->loglen > 0)
+       if (tmp_len > 0) {
+               if (logbuf->loglen + (size_t) tmp_len >= logbuf->logcap) {
+                       if ((size_t) tmp_len >= logbuf->logcap) {
+                               /* includes first time when logbuffer == NULL 
and logcap == 0 */
+                               char *alloc_buff;
+                               if (logbuf->loglen > 0)
+                                       logjsonInternal(logbuf->logbuffer, 
false);
+                               logbuf->logcap = (size_t) tmp_len + (size_t) 
tmp_len/2;
+                               if (logbuf->logcap < LOGLEN)
+                                       logbuf->logcap = LOGLEN;
+                               alloc_buff = GDKrealloc(logbuf->logbuffer, 
logbuf->logcap);
+                               if (alloc_buff == NULL) {
+                                       TRC_ERROR(MAL_SERVER, "Profiler JSON 
buffer reallocation failure\n");
+                                       logdel(logbuf);
+                                       va_end(va);
+                                       va_end(va2);
+                                       return false;
+                               }
+                               logbuf->logbuffer = alloc_buff;
+                               lognew(logbuf);
+                       } else {
                                logjsonInternal(logbuf->logbuffer, false);
-                       logbuf->logcap = (size_t) tmp_len + (size_t) tmp_len/2;
-                       if (logbuf->logcap < LOGLEN)
-                               logbuf->logcap = LOGLEN;
-                       alloc_buff = GDKrealloc(logbuf->logbuffer, 
logbuf->logcap);
-                       if (alloc_buff == NULL) {
-                               TRC_ERROR(MAL_SERVER, "Profiler JSON buffer 
reallocation failure\n");
-                               logdel(logbuf);
-                               va_end(va);
-                               va_end(va2);
-                               return false;
+                               lognew(logbuf);
                        }
-                       logbuf->logbuffer = alloc_buff;
-                       lognew(logbuf);
-               } else {
-                       logjsonInternal(logbuf->logbuffer, false);
-                       lognew(logbuf);
                }
+               logbuf->loglen += vsnprintf(logbuf->logbase + logbuf->loglen,
+                                                                       
logbuf->logcap - logbuf->loglen,
+                                                                       fmt, 
va2);
        }
-       logbuf->loglen += vsnprintf(logbuf->logbase + logbuf->loglen,
-                                                               logbuf->logcap 
- logbuf->loglen,
-                                                               fmt, va2);
        va_end(va);
        va_end(va2);
        return true;
@@ -326,7 +328,7 @@ prepareMalEvent(Client cntxt, MalBlkPtr 
        if (mb && pci->modname && pci->fcnname) {
                int j;
 
-               if (profilerMode == 0) {
+               if (profilerMode == 0 && stk) {
                        if (!logadd(&logbuf, ",\"args\":["))
                                goto cleanup_and_exit;
                        for(j=0; j< pci->argc; j++){
diff --git a/monetdb5/modules/atoms/url.c b/monetdb5/modules/atoms/url.c
--- a/monetdb5/modules/atoms/url.c
+++ b/monetdb5/modules/atoms/url.c
@@ -833,7 +833,7 @@ extractURLHost(str *retval, str *url, bi
        const char *h = NULL;
        const char *p = NULL;
 
-       if ((url != NULL || *url != NULL) && !strNil(*url)) {
+       if (url != NULL && *url != NULL && !strNil(*url)) {
                if ((s = skip_scheme(*url)) != NULL &&
                        (s = skip_authority(s, NULL, NULL, &h, &p)) != NULL &&
                        h != NULL)
diff --git a/monetdb5/modules/atoms/uuid.c b/monetdb5/modules/atoms/uuid.c
--- a/monetdb5/modules/atoms/uuid.c
+++ b/monetdb5/modules/atoms/uuid.c
@@ -65,10 +65,14 @@ UUIDgenerateUuid_internal(uuid *u)
                /* generate something like this:
                 * cefa7a9c-1dd2-41b2-8350-880020adbeef
                 * ("%08x-%04x-%04x-%04x-%012x") */
-               for (int i = 0; i < 16; i++) {
+               for (int i = 0; i < 16; i += 2) {
+#ifdef __COVERITY__
+                       int r = 0;
+#else
                        int r = rand();
-                       u->u[i++] = (unsigned char) (r >> 8);
-                       u->u[i++] = (unsigned char) r;
+#endif
+                       u->u[i] = (unsigned char) (r >> 8);
+                       u->u[i+1] = (unsigned char) r;
                }
                /* make sure this is a variant 1 UUID (RFC 4122/DCE 1.1) */
                u->u[8] = (u->u[8] & 0x3F) | 0x80;
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
@@ -509,7 +509,8 @@ CLTqueryTimeout(Client cntxt, MalBlkPtr 
                lng timeout_micro = GDKdebug & FORCEMITOMASK && qto == 1 ? 1000 
: (lng) qto * 1000000;
                mal_clients[idx].querytimeout = timeout_micro;
                QryCtx *qry_ctx = MT_thread_get_qry_ctx();
-               qry_ctx->querytimeout = timeout_micro;
+               if (qry_ctx)
+                       qry_ctx->querytimeout = timeout_micro;
        }
        MT_lock_unset(&mal_contextLock);
        return msg;
@@ -535,7 +536,8 @@ CLTqueryTimeoutMicro(Client cntxt, MalBl
        else {
                mal_clients[idx].querytimeout = qto;
                QryCtx *qry_ctx = MT_thread_get_qry_ctx();
-               qry_ctx->querytimeout = qto;
+               if (qry_ctx)
+                       qry_ctx->querytimeout = qto;
        }
        MT_lock_unset(&mal_contextLock);
        return msg;
diff --git a/monetdb5/modules/mal/mkey.c b/monetdb5/modules/mal/mkey.c
--- a/monetdb5/modules/mal/mkey.c
+++ b/monetdb5/modules/mal/mkey.c
@@ -287,7 +287,8 @@ bailout:
                BBPunfix(b->batCacheid);
        if (bs)
                BBPunfix(bs->batCacheid);
-       if (bn && !msg) {
+       if (bn) {
+               assert(msg == MAL_SUCCEED);
                BATsetcount(bn, ci.ncand);
                bn->tnonil = false;
                bn->tnil = false;
@@ -296,8 +297,6 @@ bailout:
                bn->trevsorted = BATcount(bn) <= 1;
                *res = bn->batCacheid;
                BBPkeepref(bn);
-       } else if (bn) {
-               BBPreclaim(bn);
        }
        return msg;
 }
@@ -488,7 +487,8 @@ bailout:
                BBPunfix(s1->batCacheid);
        if (s2)
                BBPunfix(s2->batCacheid);
-       if (bn && !msg) {
+       if (bn) {
+               assert(msg == MAL_SUCCEED);
                BATsetcount(bn, ci1.ncand);
                bn->tnonil = false;
                bn->tnil = false;
@@ -497,8 +497,6 @@ bailout:
                bn->trevsorted = BATcount(bn) <= 1;
                *res = bn->batCacheid;
                BBPkeepref(bn);
-       } else if (bn) {
-               BBPreclaim(bn);
        }
        return msg;
 }
@@ -583,7 +581,8 @@ bailout:
                BBPunfix(hb->batCacheid);
        if (bs)
                BBPunfix(bs->batCacheid);
-       if (bn && !msg) {
+       if (bn) {
+               assert(msg == MAL_SUCCEED);
                BATsetcount(bn, ci.ncand);
                bn->tnonil = false;
                bn->tnil = false;
@@ -592,8 +591,6 @@ bailout:
                bn->trevsorted = BATcount(bn) <= 1;
                *res = bn->batCacheid;
                BBPkeepref(bn);
-       } else if (bn) {
-               BBPreclaim(bn);
        }
        return msg;
 }
@@ -690,7 +687,8 @@ bailout:
                BBPunfix(b->batCacheid);
        if (bs)
                BBPunfix(bs->batCacheid);
-       if (bn && !msg) {
+       if (bn) {
+               assert(msg == MAL_SUCCEED);
                BATsetcount(bn, ci.ncand);
                bn->tnonil = false;
                bn->tnil = false;
@@ -699,8 +697,6 @@ bailout:
                bn->trevsorted = BATcount(bn) <= 1;
                *res = bn->batCacheid;
                BBPkeepref(bn);
-       } else if (bn) {
-               BBPreclaim(bn);
        }
        return msg;
 }
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to