Changeset: 4aff55736f9b for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4aff55736f9b
Modified Files:
        geom/monetdb5/geom.c
        monetdb5/modules/atoms/blob.c
        monetdb5/modules/atoms/inet.c
        monetdb5/modules/atoms/uuid.c
        monetdb5/modules/atoms/xml.c
Branch: default
Log Message:

Defense lines for failing malloc()


diffs (226 lines):

diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -12,6 +12,7 @@
  */
 
 #include "geom.h"
+#include "mal_exception.h"
 
 int TYPE_mbr;
 
@@ -1745,8 +1746,9 @@ dumpPointsPoint(BAT *idBAT, BAT *geomBAT
        str err = MAL_SUCCEED;
 
        (*lvl)++;
-       // FIXME unchecked_malloc GDKmalloc can return NULL
        newPath = GDKmalloc(pathLength + lvlDigitsNum + 1);
+       if( newPath == NULL)
+               throw(MAL, "geom.PointsPoint", MAL_MALLOC_FAIL);
        sprintf(newPath, "%s%u", path, *lvl);
 
        if (BUNappend(idBAT, newPath, TRUE) != GDK_SUCCEED ||
@@ -1805,8 +1807,9 @@ dumpPointsPolygon(BAT *idBAT, BAT *geomB
                throw(MAL, "geom.DumpPoints", "GEOSGetExteriorRing failed");
 
        (*lvl)++;
-       // FIXME unchecked_malloc GDKmalloc can return NULL
        newPath = GDKmalloc(pathLength + lvlDigitsNum + extraLength + 1);
+       if( newPath == NULL)
+               throw(MAL,"geom.dumpPointsPolygon",MAL_MALLOC_FAIL);
        sprintf(newPath, "%s%u%s", path, *lvl, extraStr);
 
        //get the points in the exterior ring
@@ -1858,8 +1861,9 @@ dumpPointsMultiGeometry(BAT *idBAT, BAT 
                multiGeometry = GEOSGetGeometryN(geosGeometry, i);
                lvl++;
 
-               // FIXME unchecked_malloc GDKmalloc can return NULL
                newPath = GDKmalloc(pathLength + lvlDigitsNum + extraLength + 
1);
+               if( newPath == NULL)
+                       throw(MAL,"geom.dumpPointsGeometry",MAL_MALLOC_FAIL);
                sprintf(newPath, "%s%u%s", path, lvl, extraStr);
 
                //*secondLevel = 0;
@@ -2166,8 +2170,9 @@ wkbFROMSTR_withSRID(char *geomWKT, int *
        if (strncasecmp(geomWKT, polyhedralSurface, strlen(polyhedralSurface)) 
== 0) {
                size_t sizeOfInfo = strlen(geomWKT) - strlen(polyhedralSurface);
                geomWKT_original = geomWKT;
-               // FIXME unchecked_malloc GDKmalloc can return NULL
                geomWKT = GDKmalloc(sizeOfInfo + strlen(multiPolygon) + 1);
+               if( geomWKT == NULL)
+                       throw(MAL,"geomWKT",MAL_MALLOC_FAIL);
                strcpy(geomWKT, multiPolygon);
                memcpy(geomWKT + strlen(multiPolygon), 
&geomWKT_original[strlen(polyhedralSurface)], sizeOfInfo);
                geomWKT[sizeOfInfo + strlen(multiPolygon)] = '\0';
@@ -2221,8 +2226,11 @@ wkbaFROMSTR_withSRID(char *fromStr, int 
        //read the number of items from the beginning of the string
        memcpy(&items, fromStr, sizeof(int));
        skipBytes += sizeof(int);
-       // FIXME unchecked_malloc GDKmalloc can return NULL
        *toArray = GDKmalloc(wkba_size(items));
+       if( *toArray == NULL){
+               GDKerror("FROMSTR_withSRID" MAL_MALLOC_FAIL);
+               return 0;
+       }
 
        for (i = 0; i < items; i++) {
                size_t parsedBytes;
@@ -5058,8 +5066,11 @@ wkbTOSTR(char **geomWKT, int *len, wkb *
                if (*len < (int) dstStrLen + 1) {
                        *len = (int) dstStrLen + 1;
                        GDKfree(*geomWKT);
-                       // FIXME unchecked_malloc GDKmalloc can return NULL
                        *geomWKT = GDKmalloc(*len);
+                       if( *geomWKT == NULL){
+                               GDKerror("wkbTOSTR" MAL_MALLOC_FAIL);
+                               return 0;
+                       }
                }
                snprintf(*geomWKT, *len, "\"%s\"", wkt);
                GEOSFree(wkt);
@@ -5067,6 +5078,10 @@ wkbTOSTR(char **geomWKT, int *len, wkb *
                if (*len < 4) {
                        GDKfree(*geomWKT);
                        *geomWKT = GDKmalloc(*len = 4);
+                       if( *geomWKT == NULL){
+                               GDKerror("wkbTOSTR" MAL_MALLOC_FAIL);
+                               return 0;
+                       }
                }
                strcpy(*geomWKT, "nil");
        }
@@ -5224,8 +5239,11 @@ mbrTOSTR(char **dst, int *len, mbr *atom
 
        if (*len < (int) dstStrLen + 1 || *dst == NULL) {
                GDKfree(*dst);
-               // FIXME unchecked_malloc GDKmalloc can return NULL
                *dst = GDKmalloc(*len = (int) dstStrLen + 1);
+               if( *dst == NULL){
+                       GDKerror("mbrTOSTR" MAL_MALLOC_FAIL);
+                       return 0;
+               }
        }
 
        if (dstStrLen > 3)
@@ -5266,8 +5284,11 @@ mbrFROMSTR(char *src, int *len, mbr **at
        if (*len < (int) sizeof(mbr)) {
                if (*atom)
                        GDKfree(*atom);
-               // FIXME unchecked_malloc GDKmalloc can return NULL
                *atom = GDKmalloc(*len = sizeof(mbr));
+               if( *atom == NULL){
+                       GDKerror("mbrFROMSTR" MAL_MALLOC_FAIL);
+                       return 0;
+               }
        }
        if (nil) {
                nchars = 3;
@@ -5393,9 +5414,12 @@ wkbaTOSTR(char **toStr, int *len, wkba *
        size_t dataSize;        //, skipBytes=0;
        char **partialStrs;
        char *nilStr = "nil";
-       // FIXME unchecked_malloc GDKmalloc can return NULL
        char *toStrPtr = NULL, *itemsNumStr = GDKmalloc((itemsNumDigits + 1) * 
sizeof(char));
 
+       if( itemsNumStr == NULL){
+               GDKerror("wkbaTOSTR" MAL_MALLOC_FAIL);
+               return 0;
+       }
        sprintf(itemsNumStr, "%d", items);
        dataSize = strlen(itemsNumStr);
 
@@ -5413,8 +5437,11 @@ wkbaTOSTR(char **toStr, int *len, wkba *
                        GDKfree(partialStrs);
                        if (*len < 4 || *toStr == NULL) {
                                GDKfree(*toStr);
-                               // FIXME unchecked_malloc GDKmalloc can return 
NULL
                                *toStr = GDKmalloc(*len = 4);
+                               if( *toStr == NULL){
+                                       GDKerror("wkbaTOSTR" MAL_MALLOC_FAIL);
+                                       return 0;
+                               }
                        }
                        strcpy(*toStr, "nil");
                        return 3;
@@ -5778,9 +5805,17 @@ wkbContains_point_bat(bat *out, wkb **a,
 
        /*Lets get the polygon */
        token = strtok_r(token, ")", &saveptr1);
-       // FIXME unchecked_malloc GDKmalloc can return NULL
        vert_x = GDKmalloc(POLY_NUM_VERT * sizeof(double));
+       if ( vert_x == NULL){
+               GDKfree(geom_str);
+               throw(MAL,"wkbContains_point_bat", MAL_MALLOC_FAIL);
+       }
        vert_y = GDKmalloc(POLY_NUM_VERT * sizeof(double));
+       if ( vert_y == NULL){
+               GDKfree(geom_str);
+               GDKfree(vert_x);
+               throw(MAL,"wkbContains_point_bat", MAL_MALLOC_FAIL);
+       }
 
        for (str2 = token;; str2 = NULL) {
                subtoken = strtok_r(str2, ",", &saveptr2);
diff --git a/monetdb5/modules/atoms/blob.c b/monetdb5/modules/atoms/blob.c
--- a/monetdb5/modules/atoms/blob.c
+++ b/monetdb5/modules/atoms/blob.c
@@ -577,9 +577,9 @@ BLOBblob_blob(blob **d, blob **s)
        blob *b;
 
        if( (*s)->nitems == ~(size_t) 0){
-               // FIXME unchecked_malloc BLOBnull can return NULL
-
                *d= BLOBnull();
+               if( *d == NULL)
+                       throw(MAL,"blob", MAL_MALLOC_FAIL);
        } else {
                *d= b= (blob *) GDKmalloc(len);
                if( b == NULL)
diff --git a/monetdb5/modules/atoms/inet.c b/monetdb5/modules/atoms/inet.c
--- a/monetdb5/modules/atoms/inet.c
+++ b/monetdb5/modules/atoms/inet.c
@@ -752,8 +752,9 @@ INETabbrev(str *retval, const inet *val)
                 * &:    00 00 00 00
                 * all zero, thus no bits on the right side of the mask
                 */
-               // FIXME unchecked_malloc GDKmalloc can return NULL
                ip = GDKmalloc(sizeof(char) * 19);
+               if( ip == NULL)
+                       throw(MAL,"inet.abbrev", MAL_MALLOC_FAIL);
 
                if (msk > 24) {
                        snprintf(ip, sizeof(char) * 19, "%d.%d.%d.%d/%d",
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
@@ -172,9 +172,11 @@ UUIDgenerateUuid(uuid **retval)
        uuid *u;
        int i = 0, r = 0;
 
-       if (*retval == NULL)
-               // FIXME unchecked_malloc GDKmalloc can return NULL
+       if (*retval == NULL){
                *retval = GDKmalloc(UUID_SIZE);
+               if( *retval == NULL)
+                       throw(MAL,"uuid.generate",MAL_MALLOC_FAIL);
+       }
        u = *retval;
 #ifdef HAVE_UUID
        uuid_generate(u->u);
diff --git a/monetdb5/modules/atoms/xml.c b/monetdb5/modules/atoms/xml.c
--- a/monetdb5/modules/atoms/xml.c
+++ b/monetdb5/modules/atoms/xml.c
@@ -668,8 +668,11 @@ XMLtoString(str *s, int *len, xml src)
        l = (int) strlen(src) + 1;
        if (l >= *len) {
                GDKfree(*s);
-               // FIXME unchecked_malloc GDKmalloc can return NULL
                *s = (str) GDKmalloc(l);
+               if ( *s == NULL){
+                       GDKerror("XMLtoString:" MAL_MALLOC_FAIL);
+                       return -1;
+               }
        }
        strcpy(*s, src);
        *len = l - 1;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to