Changeset: e2cd2f1b360b for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e2cd2f1b360b
Modified Files:
        gdk/gdk.h
        gdk/gdk_posix.c
        gdk/gdk_private.h
        gdk/gdk_utils.c
Branch: Jan2014
Log Message:

Attempt to make coverity happier.
And also other static code analyzers.
Define STATIC_CODE_ANALYZER when analyzing code using a static
analyzer.  This will cause GDKmalloc and friends to be replaced by
simple malloc.  (Note that you can actually use this, but that is a
bonus.)


diffs (132 lines):

diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -2277,7 +2277,7 @@ gdk_export void *GDKrealloc(void *pold, 
 gdk_export void GDKfree(void *blk);
 gdk_export str GDKstrdup(const char *s);
 
-#if !defined(NDEBUG) && !defined(__clang_analyzer__)
+#if !defined(NDEBUG) && !defined(STATIC_CODE_ANALYSIS)
 /* In debugging mode, replace GDKmalloc and other functions with a
  * version that optionally prints calling information.
  *
diff --git a/gdk/gdk_posix.c b/gdk/gdk_posix.c
--- a/gdk/gdk_posix.c
+++ b/gdk/gdk_posix.c
@@ -393,7 +393,7 @@ MT_mremap(const char *path, int mode, vo
        assert(mode & MMAP_WRITABLE);
 
        if (*new_size < old_size) {
-#ifndef __clang_analyzer__     /* hide this from static code analyzer */
+#ifndef STATIC_CODE_ANALYSIS   /* hide this from static code analyzer */
                /* shrink */
                if (munmap((char *) old_address + *new_size,
                           old_size - *new_size) < 0) {
@@ -405,7 +405,7 @@ MT_mremap(const char *path, int mode, vo
 #ifdef MMAP_DEBUG
                fprintf(stderr, "MT_mremap(%s,"PTRFMT","SZFMT","SZFMT") -> 
shrinking\n", path?path:"NULL", PTRFMTCAST old_address, old_size, *new_size);
 #endif
-#endif /* !__clang_analyzer__ */
+#endif /* !STATIC_CODE_ANALYSIS */
                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
@@ -241,7 +241,7 @@ extern MT_Lock MT_system_lock;
 
 #define SORTloop_bit(b,p,q,tl,th) SORTloop_bte(b,p,q,tl,th)
 
-#if !defined(NDEBUG) && !defined(__clang_analyzer__)
+#if !defined(NDEBUG) && !defined(STATIC_CODE_ANALYSIS)
 /* see comment in gdk.h */
 #ifdef __GNUC__
 #define GDKmallocmax(s,ps,e)                                           \
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -507,6 +507,8 @@ GDKvm_cursize(void)
        ATOMIC_SUB(GDK_vm_cursize, (ssize_t) SEG_SIZE((vmdelta), MT_VMUNITLOG), 
mbyteslock, fcn)
 #endif
 
+#ifndef STATIC_CODE_ANALYSIS
+
 static void
 GDKmemdump(void)
 {
@@ -828,7 +830,6 @@ GDKrealloc(void *blk, size_t size)
        return p;
 }
 
-
 #undef GDKstrdup
 char *
 GDKstrdup(const char *s)
@@ -841,6 +842,66 @@ GDKstrdup(const char *s)
        return n;
 }
 
+#else
+
+#define GDKmemfail(s, len)     /* nothing */
+
+void *
+GDKmallocmax(size_t size, size_t *maxsize, int emergency)
+{
+       void *ptr = malloc(size);
+       *maxsize = size;
+       if (ptr == 0 && emergency)
+               GDKfatal("fatal\n");
+       return ptr;
+}
+
+void *
+GDKmalloc(size_t size)
+{
+       return malloc(size);
+}
+
+void
+GDKfree(void *ptr)
+{
+       if (ptr)
+               free(ptr);
+}
+
+void *
+GDKzalloc(size_t size)
+{
+       void *ptr = malloc(size);
+       if (ptr)
+               memset(ptr, 0, size);
+       return ptr;
+}
+
+void *
+GDKreallocmax(void *blk, size_t size, size_t *maxsize, int emergency)
+{
+       void *ptr = realloc(blk, size);
+       *maxsize = size;
+       if (ptr == 0 && emergency)
+               GDKfatal("fatal\n");
+       return ptr;
+}
+
+void *
+GDKrealloc(void *ptr, size_t size)
+{
+       return realloc(ptr, size);
+}
+
+char *
+GDKstrdup(const char *s)
+{
+       return strdup(s);
+}
+
+#endif /* STATIC_CODE_ANALYSIS */
+
 
 /*
  * @- virtual memory
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to