Changeset: a247126e5410 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a247126e5410
Modified Files:
        tools/merovingian/daemon/discoveryrunner.c
        tools/merovingian/daemon/snapshot.c
Branch: Oct2020
Log Message:

Coverity inspired fixes.


diffs (111 lines):

diff --git a/tools/merovingian/daemon/discoveryrunner.c 
b/tools/merovingian/daemon/discoveryrunner.c
--- a/tools/merovingian/daemon/discoveryrunner.c
+++ b/tools/merovingian/daemon/discoveryrunner.c
@@ -447,7 +447,7 @@ discoveryRunner(void *d)
                        if (!_mero_keep_listening)
                                goto breakout;
                }
-               if (nread <= 0) {  /* assume only failure is EINTR */
+               if (nread <= 0 || sock < 0) {  /* assume only failure is EINTR 
*/
                        /* nothing interesting has happened */
                        buf[0] = '\0';
                        continue;
diff --git a/tools/merovingian/daemon/snapshot.c 
b/tools/merovingian/daemon/snapshot.c
--- a/tools/merovingian/daemon/snapshot.c
+++ b/tools/merovingian/daemon/snapshot.c
@@ -98,12 +98,13 @@ snapshot_database_stream(char *dbname, s
        }
 
        /* Set up the connection. Connect directly to the unix domain socket */
-       if (stats->conns == NULL || stats->conns[0].val == NULL) {
+       if (stats->conns == NULL || stats->conns[0].val == NULL ||
+               (conn = mapi_mapiuri(stats->conns[0].val, ".snapshot",
+                                                        stats->secret, "sql")) 
== NULL) {
                e = newErr("internal error: no conn");
                goto bailout;
        }
-       conn = mapi_mapiuri(stats->conns[0].val, ".snapshot", stats->secret, 
"sql");
-       if (conn == NULL || mapi_error(conn) != MOK) {
+       if (mapi_error(conn) != MOK) {
                e = newErr("connection error: %s", mapi_error_str(conn));
                goto bailout;
        }
@@ -174,12 +175,12 @@ snapshot_database_to(char *dbname, char 
        }
 
        /* Set up the connection. Connect directly to the unix domain socket */
-       if (stats->conns == NULL || stats->conns[0].val == NULL) {
+       if (stats->conns == NULL || stats->conns[0].val == NULL ||
+               (conn = mapi_mapiuri(stats->conns[0].val, ".snapshot", 
stats->secret, "sql")) == NULL) {
                e = newErr("internal error: no conn");
                goto bailout;
        }
-       conn = mapi_mapiuri(stats->conns[0].val, ".snapshot", stats->secret, 
"sql");
-       if (conn == NULL || mapi_error(conn) != MOK) {
+       if (mapi_error(conn) != MOK) {
                e = newErr("connection error: %s", mapi_error_str(conn));
                goto bailout;
        }
@@ -402,11 +403,12 @@ parse_snapshot_name_selftest(void)
        };
 
        char *errmsg = NULL;
-       char *dbname = "<uninit>";
+       char *dbname = NULL;
        time_t timestamp = 0;
        bool result;
        for (tc = &testcases[0]; tc->filename != NULL; tc++) {
-               dbname = "<uninit>";
+               free(dbname);
+               dbname = NULL;
                timestamp = 0;
                result = parse_snapshot_name(tc->filename, &dbname, &timestamp);
                if (result != tc->expected_result) {
@@ -427,14 +429,17 @@ parse_snapshot_name_selftest(void)
                }
        }
 
-       if (errmsg != NULL)
-               return newErr(
+       if (errmsg != NULL) {
+               errmsg = newErr(
                        "parse_snapshot_name selftest failure for '%s':"
                        " %s (%s, '%s', %" PRIu64 ")\n",
                        tc->filename, errmsg,
                        result ? "true" : "false",
-                       dbname,
+                       dbname ? dbname : "<uninit>",
                        (uint64_t)timestamp);
+               free(dbname);
+               return errmsg;
+       }
 
        return NO_ERR;
 }
@@ -485,17 +490,17 @@ parse_snapshot_name(const char *filename
        }
        *ts = '\0'; // chop!
 
-        // We want to interpret the timestamp as UTC.
-        // Unfortunately, mktime interprets it as Localtime.
-        time_t wrong = mktime(&tm);
+       // We want to interpret the timestamp as UTC.
+       // Unfortunately, mktime interprets it as Localtime.
+       time_t wrong = mktime(&tm);
 
-        // Let's adjust it.
-        // Take a timestamp, render it in UTC, then read back as Localtime.
+       // Let's adjust it.
+       // Take a timestamp, render it in UTC, then read back as Localtime.
        // Look at the difference.
-        time_t before = time(NULL);
-        gmtime_r(&before, &tm);
-        time_t after = mktime(&tm);
-        time_t correct = before - after + wrong;
+       time_t before = time(NULL);
+       gmtime_r(&before, &tm);
+       time_t after = mktime(&tm);
+       time_t correct = before - after + wrong;
 
        // Return the results
        *timestamp = correct;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to