Changeset: 1921da21e845 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1921da21e845
Modified Files:
        buildtools/coverity_model.c
        clients/odbc/driver/SQLGetDescField.c
        clients/odbc/driver/SQLGetStmtAttr.c
        cmake/monetdb-options.cmake
        gdk/gdk_batop.c
        gdk/gdk_bbp.c
        gdk/gdk_posix.c
        gdk/gdk_private.h
        gdk/gdk_storage.c
        gdk/gdk_utils.c
        gdk/gdk_utils.h
        geom/monetdb5/geom.c
        monetdb5/modules/kernel/batmmath.c
        monetdb5/modules/kernel/microbenchmark.c
        monetdb5/modules/kernel/mmath.c
        monetdb5/modules/mal/mal_mapi.c
        monetdb_config.h.in
        sql/backends/monet5/UDF/pyapi3/pyheader.h
        sql/include/sql_mem.h
        testing/difflib.c
        tools/merovingian/daemon/discoveryrunner.c
        tools/merovingian/daemon/forkmserver.c
        tools/merovingian/utils/utils.c
Branch: Oct2020
Log Message:

Simplifying some coverity-related code.


diffs (truncated from 468 to 300 lines):

diff --git a/buildtools/coverity_model.c b/buildtools/coverity_model.c
--- a/buildtools/coverity_model.c
+++ b/buildtools/coverity_model.c
@@ -20,8 +20,13 @@
  * author: Sjoerd Mullender
  */
 
+int
+rand(void)
+{
+       /* ignore */
+}
+
 typedef enum { GDK_FAIL, GDK_SUCCEED } gdk_return;
-typedef struct {} *MalBlkPtr;
 
 void
 GDKfree(void *blk)
@@ -137,6 +142,24 @@ GDKmremap(const char *path, int mode, vo
        return p;
 }
 
+typedef struct {} *MalBlkPtr;
+enum malexception {
+       MAL,
+       ILLARG /*,
+       OUTOFBNDS,
+       IO,
+       INVCRED,
+       OPTIMIZER,
+       STKOF,
+       SYNTAX,
+       TYPE,
+       LOADER,
+       PARSE,
+       ARITH,
+       PERMD,
+       SQL */
+};
+
 char *
 createException(enum malexception type, const char *fcn, const char *format, 
...)
 {
@@ -178,8 +201,8 @@ freeException(char *p)
 char *
 concatErrors(char *err1, const char *err2)
 {
+       char *p;
        freeException(err1);
-       char *p;
        p = __coverity_alloc_nosize__();
        __coverity_mark_as_afm_allocated__(p, "freeException");
        return p;
diff --git a/clients/odbc/driver/SQLGetDescField.c 
b/clients/odbc/driver/SQLGetDescField.c
--- a/clients/odbc/driver/SQLGetDescField.c
+++ b/clients/odbc/driver/SQLGetDescField.c
@@ -126,7 +126,7 @@ MNDBGetDescField(ODBCDesc *desc,
                WriteData(ValuePtr, rec->sql_desc_concise_type, SQLSMALLINT);
                return SQL_SUCCESS;
        case SQL_DESC_DATA_PTR:                 /* SQLPOINTER */
-#ifndef STATIC_CODE_ANALYSIS
+#ifndef __COVERITY__
                /* Coverity doesn't like the debug print in WriteData,
                 * so we hide this whole thing */
                if (!isIRD(desc))
diff --git a/clients/odbc/driver/SQLGetStmtAttr.c 
b/clients/odbc/driver/SQLGetStmtAttr.c
--- a/clients/odbc/driver/SQLGetStmtAttr.c
+++ b/clients/odbc/driver/SQLGetStmtAttr.c
@@ -41,7 +41,7 @@ MNDBGetStmtAttr(ODBCStmt *stmt,
         * StringLengthPtr */
 
        switch (Attribute) {
-#ifndef STATIC_CODE_ANALYSIS
+#ifndef __COVERITY__
        /* Coverity doesn't like the debug print in WriteData, so we
         * hide this whole thing */
        case SQL_ATTR_APP_PARAM_DESC:           /* SQLHANDLE */
@@ -72,7 +72,7 @@ MNDBGetStmtAttr(ODBCStmt *stmt,
                /* SQL_CURSOR_TYPE */
                WriteData(ValuePtr, stmt->cursorType, SQLULEN);
                break;
-#ifndef STATIC_CODE_ANALYSIS
+#ifndef __COVERITY__
        /* Coverity doesn't like the debug print in WriteData, so we
         * hide this whole thing */
        case SQL_ATTR_IMP_PARAM_DESC:           /* SQLHANDLE */
diff --git a/cmake/monetdb-options.cmake b/cmake/monetdb-options.cmake
--- a/cmake/monetdb-options.cmake
+++ b/cmake/monetdb-options.cmake
@@ -65,10 +65,6 @@ option(SANITIZER
   "Enable support for the GCC address sanitizer (default=OFF)"
   OFF)
 
-option(STATIC_CODE_ANALYSIS
-  "configure for static code analysis (use only if you know what you are 
doing) (default=OFF)"
-  OFF)
-
 option(STRICT
   "Enable strict compiler flags (default=ON for development sources, OFF for 
tarball installation)"
   "${DEVELOPMENT}")
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -49,10 +49,6 @@ unshare_string_heap(BAT *b)
  * it makes sense to just quickly copy the whole string heap instead
  * of inserting individual strings.  See the comments in the code for
  * more information. */
-#ifdef STATIC_CODE_ANALYSIS
-#define rand()         0
-#endif
-
 static gdk_return
 insert_string_bat(BAT *b, BAT *n, struct canditer *ci, bool force, bool 
mayshare)
 {
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -965,7 +965,7 @@ BBPreadEntries(FILE *fp, unsigned bbpver
                }
                /* tailname is ignored */
                strcpy_len(BBP_physical(bid), filename, 
sizeof(BBP_physical(bid)));
-#ifdef STATIC_CODE_ANALYSIS
+#ifdef __COVERITY__
                /* help coverity */
                BBP_physical(bid)[sizeof(BBP_physical(bid)) - 1] = 0;
 #endif
diff --git a/gdk/gdk_posix.c b/gdk/gdk_posix.c
--- a/gdk/gdk_posix.c
+++ b/gdk/gdk_posix.c
@@ -373,7 +373,7 @@ MT_mremap(const char *path, int mode, vo
        assert(mode & MMAP_WRITABLE);
 
        if (*new_size < old_size) {
-#ifndef STATIC_CODE_ANALYSIS   /* hide this from static code analyzer */
+#ifndef __COVERITY__   /* hide this from static code analyzer */
                /* shrink */
                VALGRIND_RESIZEINPLACE_BLOCK(old_address, old_size, *new_size, 
0);
                if (munmap((char *) old_address + *new_size,
@@ -388,7 +388,7 @@ MT_mremap(const char *path, int mode, vo
                if (path && truncate(path, *new_size) < 0)
                        TRC_WARNING(GDK, "MT_mremap(%s): truncate failed: %s\n",
                                    path, GDKstrerror(errno, (char[64]){0}, 
64));
-#endif /* !STATIC_CODE_ANALYSIS */
+#endif /* !__COVERITY__ */
                return old_address;
        }
        if (*new_size == old_size) {
diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h
--- a/gdk/gdk_private.h
+++ b/gdk/gdk_private.h
@@ -374,7 +374,7 @@ extern MT_Lock GDKtmLock;
  * incompatible) */
 #define EXTRALEN ((SIZEOF_BUN + GDK_VARALIGN - 1) & ~(GDK_VARALIGN - 1))
 
-#if !defined(NDEBUG) && !defined(STATIC_CODE_ANALYSIS)
+#if !defined(NDEBUG) && !defined(__COVERITY__)
 /* see comment in gdk.h */
 #ifdef __GNUC__
 #define GDKmremap(p, m, oa, os, ns)                                    \
diff --git a/gdk/gdk_storage.c b/gdk/gdk_storage.c
--- a/gdk/gdk_storage.c
+++ b/gdk/gdk_storage.c
@@ -350,7 +350,7 @@ GDKextendf(int fd, size_t size, const ch
        int t0 = GDKms();
 
        assert(!GDKinmemory());
-#ifdef STATIC_CODE_ANALYSIS
+#ifdef __COVERITY__
        if (fd < 0)             /* in real life, if fd < 0, fstat will fail */
                return GDK_FAIL;
 #endif
@@ -544,7 +544,7 @@ GDKload(int farmid, const char *nme, con
                                        n = read(fd, dst, (unsigned) MIN(1 << 
30, n_expected));
                                        if (n < 0)
                                                GDKsyserror("GDKload: cannot 
read: name=%s, ext=%s, %zu bytes missing.\n", nme, ext ? ext : "", (size_t) 
n_expected);
-#ifndef STATIC_CODE_ANALYSIS
+#ifndef __COVERITY__
                                        /* Coverity doesn't seem to
                                         * recognize that we're just
                                         * printing the value of ptr,
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -628,7 +628,7 @@ MT_init(void)
 static int THRinit(void);
 static gdk_return GDKlockHome(int farmid);
 
-#ifndef STATIC_CODE_ANALYSIS
+#ifndef __COVERITY__
 #ifndef NDEBUG
 static MT_Lock mallocsuccesslock = MT_LOCK_INITIALIZER("mallocsuccesslk");
 #endif
@@ -1308,7 +1308,7 @@ GDKfatal(const char *format, ...)
        vsnprintf(message + len, sizeof(message) - (len + 2), format, ap);
        va_end(ap);
 
-#ifndef STATIC_CODE_ANALYSIS
+#ifndef __COVERITY__
        if (GDKfataljumpenable) {
                // in embedded mode, we really don't want to kill our host
                GDKfatalmsg = GDKstrdup(message);
@@ -1663,8 +1663,6 @@ GDKvm_cursize(void)
 #define memdec(vmdelta)                                                        
\
        (void) ATOMIC_SUB(&GDK_vm_cursize, (ssize_t) SEG_SIZE((vmdelta), 
MT_VMUNITLOG))
 
-#ifndef STATIC_CODE_ANALYSIS
-
 /* Memory allocation
  *
  * The functions GDKmalloc, GDKzalloc, GDKrealloc, GDKstrdup, and
@@ -1904,66 +1902,6 @@ GDKrealloc(void *s, size_t size)
        return s;
 }
 
-#else
-
-void *
-GDKmalloc(size_t size)
-{
-       void *p = malloc(size);
-       if (p == NULL)
-               GDKsyserror("failed for %zu bytes", size);
-       return p;
-}
-
-void
-GDKfree(void *ptr)
-{
-       if (ptr)
-               free(ptr);
-}
-
-void *
-GDKzalloc(size_t size)
-{
-       void *ptr = calloc(size, 1);
-       if (ptr == NULL)
-               GDKerror("failed for %zu bytes", size);
-       return ptr;
-}
-
-void *
-GDKrealloc(void *ptr, size_t size)
-{
-       void *p = realloc(ptr, size);
-       if (p == NULL)
-               GDKerror("failed for %zu bytes", size);
-       return p;
-}
-
-char *
-GDKstrdup(const char *s)
-{
-       char *p = strdup(s);
-       if (p == NULL)
-               GDKerror("failed for %s\n", s);
-       return p;
-}
-
-char *
-GDKstrndup(const char *s, size_t size)
-{
-       char *p = malloc(size + 1);
-       if (p == NULL) {
-               GDKsyserror("failed for %s\n", s);
-               return NULL;
-       }
-       memcpy(p, s, size);
-       p[size] = 0;
-       return p;
-}
-
-#endif /* STATIC_CODE_ANALYSIS */
-
 void
 GDKsetmallocsuccesscount(lng count)
 {
diff --git a/gdk/gdk_utils.h b/gdk/gdk_utils.h
--- a/gdk/gdk_utils.h
+++ b/gdk/gdk_utils.h
@@ -133,7 +133,7 @@ gdk_export lng GDKusec(void);
 gdk_export int GDKms(void);
 
 
-#if !defined(NDEBUG) && !defined(STATIC_CODE_ANALYSIS)
+#if !defined(NDEBUG) && !defined(__COVERITY__)
 /* In debugging mode, replace GDKmalloc and other functions with a
  * version that optionally prints calling information.
  *
diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -1602,7 +1602,7 @@ dumpGeometriesSingle(BAT *idBAT, BAT *ge
                snprintf(newPath, lvlDigitsNum + 1, "%u", *lvl);
        } else {
                //remove the comma at the end of the path
-#ifdef STATIC_CODE_ANALYSIS
+#ifdef __COVERITY__
                /* coverity complains about the allocated space being
                 * too small, but we just want to reduce the length of
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to