Changeset: fb152ad2096b for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=fb152ad2096b
Modified Files:
        configure.ag
        monetdb5/mal/mal_import.c
        sql/backends/monet5/LSST/lsst.c
        sql/backends/monet5/sql_cast.c
        sql/backends/monet5/sql_result.c
        sql/backends/monet5/vaults/fits.c
Branch: default
Log Message:

Merge with Jan2014 branch.


diffs (truncated from 406 to 300 lines):

diff --git a/configure.ag b/configure.ag
--- a/configure.ag
+++ b/configure.ag
@@ -281,6 +281,10 @@ case $enable_control in
        *) enable_control=no;;
 esac
 
+AC_ARG_ENABLE(static-analysis,
+       AS_HELP_STRING([--enable-static-analysis], [configure for static code 
analysis (use only if you know what you are doing)]),
+       AC_DEFINE([STATIC_CODE_ANALYSIS], 1, [compiling for static code 
analysis]))
+
 dnl RIPEMD160 is patent free, academic and European, but unfortunately
 dnl can't use it by default, as that would exclude JDBC usage (Java
 dnl doesn't natively support RIPEMD160).
diff --git a/monetdb5/mal/mal_import.c b/monetdb5/mal/mal_import.c
--- a/monetdb5/mal/mal_import.c
+++ b/monetdb5/mal/mal_import.c
@@ -202,8 +202,10 @@ malInclude(Client c, str name, int listi
                        if ((s = malLoadScript(c, filename, &c->fdin)) == 0) {
                                parseMAL(c, c->curprg);
                                bstream_destroy(c->fdin);
-                       } else
+                       } else {
                                GDKfree(s); // not interested in error here
+                               s = MAL_SUCCEED;
+                       }
                        if (p)
                                filename = p + 1;
                } while (p);
diff --git a/sql/backends/monet5/LSST/lsst.c b/sql/backends/monet5/LSST/lsst.c
--- a/sql/backends/monet5/LSST/lsst.c
+++ b/sql/backends/monet5/LSST/lsst.c
@@ -409,7 +409,7 @@ str qserv_ptInSphPoly(MalBlkPtr mb, MalS
        for (i = 3; i <pci->argc; ++i) 
                nv[i-3] =  *(dbl*) getArgReference(stk,pci,i);
        _qserv_computeEdges(edges,nv, nedges);
-       
+       GDKfree(nv);
 
        /* Transform input position from spherical coordinates
           to a unit cartesian vector. */
diff --git a/sql/backends/monet5/sql_cast.c b/sql/backends/monet5/sql_cast.c
--- a/sql/backends/monet5/sql_cast.c
+++ b/sql/backends/monet5/sql_cast.c
@@ -459,12 +459,17 @@ SQLstr_cast_(str *res, mvc *m, int eclas
 
        if (tpe != TYPE_str) {
                r = GDKmalloc(sz);
+               if (r == NULL)
+                       throw(SQL, "str_cast", MAL_MALLOC_FAIL);
                sz = convert2str(m, eclass, d, s, has_tz, p, tpe, &r, sz);
        } else {
                str v = (str) p;
                STRLength(&sz, &v);
-               if (len == 0 || (sz >= 0 && sz <= len))
+               if (len == 0 || (sz >= 0 && sz <= len)) {
                        r = GDKstrdup(v);
+                       if (r == NULL)
+                               throw(SQL, "str_cast", MAL_MALLOC_FAIL);
+               }
        }
        if ((len > 0 && sz > len) || sz < 0) {
                if (r)
@@ -473,6 +478,8 @@ SQLstr_cast_(str *res, mvc *m, int eclas
                        throw(SQL, "str_cast", "22001!value too long for type 
(var)char(%d)", len);
                } else {
                        r = GDKstrdup(str_nil);
+                       if (r == NULL)
+                               throw(SQL, "str_cast", MAL_MALLOC_FAIL);
                }
        }
        *res = r;
@@ -541,6 +548,7 @@ SQLbatstr_cast(Client cntxt, MalBlkPtr m
                        break;
                BUNins(dst, BUNhead(bi, p), r, FALSE);
                GDKfree(r);
+               r = NULL;
        }
        BBPkeepref(*res = dst->batCacheid);
        BBPunfix(b->batCacheid);
diff --git a/sql/backends/monet5/sql_result.c b/sql/backends/monet5/sql_result.c
--- a/sql/backends/monet5/sql_result.c
+++ b/sql/backends/monet5/sql_result.c
@@ -34,49 +34,61 @@
 #define llabs(x)       ((x) < 0 ? -(x) : (x))
 #endif
 
-#define DEC_TOSTR(X) \
-       char buf[32]; \
-       X v = *(const X*)a; \
-       int scale = (int)(ptrdiff_t)extra, cur = 31, neg = (v<0)?1:0, i, done = 
0; \
-       int l; \
-       if (v == X##_nil) { \
-               if (*len < 5){ \
-                       if (*Buf) \
-                               GDKfree(*Buf); \
-                       *len = 5; \
-                       *Buf = GDKmalloc(*len); \
-               } \
-               strcpy(*Buf, "NULL"); \
-               return 4; \
-       } \
-       if (v<0) \
-               v = -v; \
-       buf[cur--] = 0; \
-       if (scale){ \
-               for (i=0; i<scale; i++) { \
-                       buf[cur--] = (char) (v%10 + '0'); \
-                       v /= 10; \
-               } \
-               buf[cur--] = '.'; \
-       } \
-       while (v) { \
-               buf[cur--] = (char ) (v%10 + '0'); \
-               v /= 10; \
-               done = 1; \
-       } \
-       if (!done) \
-               buf[cur--] = '0'; \
-       if (neg) \
-               buf[cur--] = '-'; \
-       l = (32-cur-1); \
-       if (*len < l){ \
-               if (*Buf) \
-                       GDKfree(*Buf); \
-               *len = l+1; \
-               *Buf = GDKmalloc(*len); \
-       } \
-       strcpy(*Buf, buf+cur+1); \
-       return l-1;
+#define DEC_TOSTR(TYPE)                                                        
\
+       do {                                                            \
+               char buf[32];                                           \
+               TYPE v = *(const TYPE *) a;                             \
+               int scale = (int) (ptrdiff_t) extra;                    \
+               int cur = 31, i, done = 0;                              \
+               int neg = v < 0;                                        \
+               int l;                                                  \
+               if (v == TYPE##_nil) {                                  \
+                       if (*len < 5){                                  \
+                               if (*Buf)                               \
+                                       GDKfree(*Buf);                  \
+                               *len = 5;                               \
+                               *Buf = GDKmalloc(*len);                 \
+                               if (*Buf == NULL) {                     \
+                                       GDKerror("Allocation failed\n"); \
+                                       return 0;                       \
+                               }                                       \
+                       }                                               \
+                       strcpy(*Buf, "NULL");                           \
+                       return 4;                                       \
+               }                                                       \
+               if (v<0)                                                \
+                       v = -v;                                         \
+               buf[cur--] = 0;                                         \
+               if (scale){                                             \
+                       for (i=0; i<scale; i++) {                       \
+                               buf[cur--] = (char) (v%10 + '0');       \
+                               v /= 10;                                \
+                       }                                               \
+                       buf[cur--] = '.';                               \
+               }                                                       \
+               while (v) {                                             \
+                       buf[cur--] = (char ) (v%10 + '0');              \
+                       v /= 10;                                        \
+                       done = 1;                                       \
+               }                                                       \
+               if (!done)                                              \
+                       buf[cur--] = '0';                               \
+               if (neg)                                                \
+                       buf[cur--] = '-';                               \
+               l = (32-cur-1);                                         \
+               if (*len < l){                                          \
+                       if (*Buf)                                       \
+                               GDKfree(*Buf);                          \
+                       *len = l+1;                                     \
+                       *Buf = GDKmalloc(*len);                         \
+                       if (*Buf == NULL) {                             \
+                               GDKerror("Allocation failed\n");        \
+                               return 0;                               \
+                       }                                               \
+               }                                                       \
+               strcpy(*Buf, buf+cur+1);                                \
+               return l-1;                                             \
+       } while (0)
 
 static int
 dec_tostr(void *extra, char **Buf, int *len, int type, const void *a)
@@ -130,6 +142,10 @@ sql_time_tostr(void *TS_RES, char **buf,
                        if (*buf)
                                GDKfree(*buf);
                        *buf = (str) GDKmalloc(*len = 4);
+                       if (*buf == NULL) {
+                               GDKerror("Allocation failed\n");
+                               return 0;
+                       }
                }
                strcpy(*buf, s1);
                return len1;
@@ -144,6 +160,10 @@ sql_time_tostr(void *TS_RES, char **buf,
                if (*buf)
                        GDKfree(*buf);
                *buf = (str) GDKmalloc(*len = len1 + 8);
+               if (*buf == NULL) {
+                       GDKerror("Allocation failed\n");
+                       return 0;
+               }
        }
        s = *buf;
        strcpy(s, buf1);
@@ -191,6 +211,10 @@ sql_timestamp_tostr(void *TS_RES, char *
                if (*buf)
                        GDKfree(*buf);
                *buf = (str) GDKmalloc(*len = len1 + len2 + 8);
+               if (*buf == NULL) {
+                       GDKerror("Allocation failed\n");
+                       return 0;
+               }
        }
        s = *buf;
        strcpy(s, buf1);
@@ -356,58 +380,61 @@ bat_max_lnglength(BAT *b)
        return ret;
 }
 
-#define DEC_FRSTR(X) \
-       sql_column *col = c->extra; \
-       sql_subtype *t = &col->type; \
- \
-       unsigned int i, neg = 0; \
-       X *r; \
-       X res = 0; \
-       if (*s == '-'){ \
-               neg = 1; \
-               s++; \
-       } else if (*s == '+'){ \
-               neg = 0; \
-               s++; \
-       } \
-       for (i = 0; *s && *s != '.' && ((res == 0 && *s == '0') || i < 
t->digits - t->scale); s++) { \
-               if (!*s || *s < '0' || *s > '9')  \
-                       return NULL; \
-               res *= 10; \
-               res += (*s-'0'); \
-               if (res) \
-                       i++; \
-       } \
-       if (!*s && t->scale) { \
-               for( i = 0; i < t->scale; i++) { \
-                       res *= 10; \
-               } \
-       } \
-       if (*s) { \
-               if (*s != '.')  \
-                       return NULL; \
-               s++; \
-               for( i = 0; *s && i < t->scale; i++, s++) { \
-                       if (*s < '0' || *s > '9')  \
-                               return NULL; \
-                       res *= 10; \
-                       res += (*s-'0'); \
-               } \
-               for( ; i < t->scale; i++) { \
-                       res *= 10; \
-               } \
-       } \
-       if (*s)  \
-               return NULL; \
-       r = c->data; \
-       if (!r) \
-               r = (X*)GDKmalloc(sizeof(X)); \
-       c->data = r; \
-       if (neg) \
-               *r = -res; \
-       else \
-               *r = res; \
-       return (void *) r;
+#define DEC_FRSTR(X)                                                   \
+       do {                                                            \
+               sql_column *col = c->extra;                             \
+               sql_subtype *t = &col->type;                            \
+                                                                       \
+               unsigned int i, neg = 0;                                \
+               X *r;                                                   \
+               X res = 0;                                              \
+               if (*s == '-'){                                         \
+                       neg = 1;                                        \
+                       s++;                                            \
+               } else if (*s == '+'){                                  \
+                       neg = 0;                                        \
+                       s++;                                            \
+               }                                                       \
+               for (i = 0; *s && *s != '.' && ((res == 0 && *s == '0') || i < 
t->digits - t->scale); s++) { \
+                       if (!*s || *s < '0' || *s > '9')                \
+                               return NULL;                            \
+                       res *= 10;                                      \
+                       res += (*s-'0');                                \
+                       if (res)                                        \
+                               i++;                                    \
+               }                                                       \
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to