Graphics module Null Checks added 20/18520/3
Dhruv Khattar [Fri, 26 Aug 2016 15:50:05 +0000 (20:50 +0530)]
Change-Id: Ie93fea82a9333aac98c32afcde9b723d6bc5f09f

13 files changed:
scilab/modules/graphics/sci_gateway/c/sci_delete.c
scilab/modules/graphics/sci_gateway/c/sci_drawaxis.c
scilab/modules/graphics/sci_gateway/c/sci_zoom_rect.c
scilab/modules/graphics/src/c/BuildObjects.c
scilab/modules/graphics/src/c/Champ.c
scilab/modules/graphics/src/c/DrawObjects.c
scilab/modules/graphics/src/c/Format.c
scilab/modules/graphics/src/c/Plo2dn.c
scilab/modules/graphics/src/c/StringBox.c
scilab/modules/graphics/src/c/axesScale.c
scilab/modules/graphics/src/c/getHandleProperty/get_data_property.c
scilab/modules/graphics/src/c/getHandleProperty/set_format_n_property.c
scilab/modules/graphics/src/c/sciCall.c

index 8f26cc0..3712b07 100644 (file)
@@ -188,12 +188,15 @@ int sci_delete(char *fname, void* pvApiCtx)
 
                     getGraphicObjectProperty(iFigureUID, __GO_CHILDREN__, jni_int_vector, (void **)&piChildrenUID);
 
-                    for (i = 0; i < childrencount[0]; ++i)
+                    if (childrencount && piChildrenUID)
                     {
-                        getGraphicObjectProperty(piChildrenUID[i], __GO_HIDDEN__, jni_bool, (void **)&piHidden);
-                        if (iHidden == 0)
+                        for (i = 0; i < childrencount[0]; ++i)
                         {
-                            deleteGraphicObject(piChildrenUID[i]);
+                            getGraphicObjectProperty(piChildrenUID[i], __GO_HIDDEN__, jni_bool, (void **)&piHidden);
+                            if (iHidden == 0)
+                            {
+                                deleteGraphicObject(piChildrenUID[i]);
+                            }
                         }
                     }
                     /*
index c3a764f..4ba06f2 100644 (file)
@@ -249,6 +249,12 @@ int sci_drawaxis(char *fname, void* pvApiCtx)
         int iCurrentSubwinUID = getCurrentSubWin();
 
         getGraphicObjectProperty(iCurrentSubwinUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **)&bounds);
+        if (!bounds)
+        {
+            freeAllocatedSingleString(format);
+            freeAllocatedMatrixOfString(opts[8].iRows, opts[8].iCols, val);
+            return 1;
+        }
         ny = 1;
         y = y_def;
         if (dir == 'd')
index 4c6ed0c..ab8ce73 100644 (file)
@@ -211,14 +211,21 @@ int sci_zoom_rect(char *fname, void *pvApiCtx)
 
                 getGraphicObjectProperty(iFigureUID, __GO_CHILDREN__, jni_int_vector, (void **)&piChildrenUID);
 
-                for (i = 0; i < childrencount[0]; ++i)
+                if (childrencount && piChildrenUID)
                 {
-                    getGraphicObjectProperty(piChildrenUID[i], __GO_HIDDEN__, jni_bool, (void **)&piHidden);
-                    if (iHidden == 0)
+                    for (i = 0; i < childrencount[0]; ++i)
                     {
-                        status = sciZoom2D(piChildrenUID[i], rect);
+                        getGraphicObjectProperty(piChildrenUID[i], __GO_HIDDEN__, jni_bool, (void **)&piHidden);
+                        if (iHidden == 0)
+                        {
+                            status = sciZoom2D(piChildrenUID[i], rect);
+                        }
                     }
                 }
+                else
+                {
+                    status = SET_PROPERTY_ERROR;
+                }
                 if (status == SET_PROPERTY_ERROR)
                 {
                     /* error on rectangle bounds */
index 51b9a61..16b725e 100644 (file)
@@ -783,16 +783,23 @@ int ConstructCompoundSeq(int number)
      * Remove the last "number" created objects (located at the children list's head)
      * and add them to the compound in the same order
      */
-    for (i = 0; i < number; i++)
+    if (children && piNumberChildren)
     {
-        /*
-         * Set the parent-child relationship between the Compound and each aggregated object.
-         * Children are added to the Compound from the least recent to the most recent, to
-         * preserve their former ordering.
-         */
-        setGraphicObjectRelationship(iObj, children[number - i - 1]);
+        for (i = 0; i < number; i++)
+        {
+            /*
+             * Set the parent-child relationship between the Compound and each aggregated object.
+             * Children are added to the Compound from the least recent to the most recent, to
+             * preserve their former ordering.
+             */
+            setGraphicObjectRelationship(iObj, children[number - i - 1]);
+        }
+        releaseGraphicObjectProperty(__GO_CHILDREN__, children, jni_int_vector, numberChildren);
+    }
+    else
+    {
+        return -1;
     }
-    releaseGraphicObjectProperty(__GO_CHILDREN__, children, jni_int_vector, numberChildren);
 
     /* Sets the parent-child relationship for the Compound */
     setGraphicObjectRelationship(iSubwinUID, iObj);
index 7595a0d..8ad735c 100644 (file)
@@ -142,6 +142,11 @@ void champg(char *name, int colored, double *x, double *y, double *fx, double *f
 
     /* Get segs bounding box */
     getGraphicObjectProperty(iNewSegsUID, __GO_BOUNDING_BOX__, jni_double_vector, (void **)&boundingBox);
+    if (!boundingBox)
+    {
+        Scierror(999, _("%s: Could not retrive bounding box.\n"), "champg");
+        return;
+    }
 
     xx[0] = boundingBox[0];
     xx[1] = boundingBox[1];
index e58bde2..9f2f677 100644 (file)
@@ -82,6 +82,12 @@ void sciGetDisplayedBounds(int iSubWinUID,
         getGraphicObjectProperty(iSubWinUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **)&bounds);
     }
 
+    if (!bounds)
+    {
+        Scierror(999, _("Could not retrive bounds.\n"));
+        return;
+    }
+
     *xmin = bounds[0];
     *xmax = bounds[1];
     *ymin = bounds[2];
index c5b87e3..a7244b8 100644 (file)
@@ -1084,6 +1084,12 @@ int ComputeXIntervals(int iObjUID, char xy_type, double ** vector, int * N, int
         nval = ny;
     }
 
+    if (!val)
+    {
+        Scierror(999, _("%s: Cannot get coordinates.\n"), "ComputeXIntervals");
+        return -1;
+    }
+
     if (xy_type == 'v')
     {
         *N = n = nval;
@@ -1204,7 +1210,7 @@ StringMatrix * computeDefaultTicsLabels(int iObjUID)
      * If different from the empty string, the format is already specified,
      * if equal, it needs to be computed.
      */
-    if (strcmp(c_format, "") == 0)
+    if (c_format && strcmp(c_format, "") == 0)
     {
         ComputeC_format(iObjUID, tempFormat);
         c_format = tempFormat;
index b7cbafd..64b562c 100644 (file)
@@ -628,11 +628,17 @@ BOOL update_specification_bounds(int iSubwinUID, double rect[6], int flag)
     if (flag != 3)
     {
         getGraphicObjectProperty(iSubwinUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **)&dataBounds);
-
-        rect[4] = dataBounds[4];
-        rect[5] = dataBounds[5];
-
-        releaseGraphicObjectProperty(__GO_DATA_BOUNDS__, dataBounds, jni_double_vector, 6);
+        
+        if (dataBounds)
+        {
+            rect[4] = dataBounds[4];
+            rect[5] = dataBounds[5];
+            releaseGraphicObjectProperty(__GO_DATA_BOUNDS__, dataBounds, jni_double_vector, 6);
+        }
+        else
+        {
+            return FALSE;
+        }
     }
 
     setGraphicObjectProperty(iSubwinUID, __GO_DATA_BOUNDS__, rect, jni_double_vector, 6);
index 38cf2bd..46518df 100644 (file)
@@ -88,17 +88,20 @@ void getTextBoundingBox(char ** text, int nbRow, int nbCol,
      * but using a rotation matrix corresponding to the default rotation angles (view == 2d)
      */
 
-    corners[1][0] = textCorners[0];
-    corners[1][1] = textCorners[1];
+    if (textCorners)
+    {
+        corners[1][0] = textCorners[0];
+        corners[1][1] = textCorners[1];
 
-    corners[0][0] = textCorners[3];
-    corners[0][1] = textCorners[4];
+        corners[0][0] = textCorners[3];
+        corners[0][1] = textCorners[4];
 
-    corners[3][0] = textCorners[6];
-    corners[3][1] = textCorners[7];
+        corners[3][0] = textCorners[6];
+        corners[3][1] = textCorners[7];
 
-    corners[2][0] = textCorners[9];
-    corners[2][1] = textCorners[10];
+        corners[2][0] = textCorners[9];
+        corners[2][1] = textCorners[10];
+    }
 
     deleteGraphicObject(iTextUID);
 }
index 99c903f..86a1770 100644 (file)
@@ -52,12 +52,18 @@ int sciZoom2D(int iSubwinUID, const double zoomRect[4])
         // add Z scale to data bounds.
         getGraphicObjectProperty(iSubwinUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **) &zoomBox);
 
-        zoomBox[0] = zoomRect[0];
-        zoomBox[1] = zoomRect[1];
-        zoomBox[2] = zoomRect[2];
-        zoomBox[3] = zoomRect[3];
-
-        return sciZoom3D(iSubwinUID, zoomBox);
+        if (zoomBox)
+        {
+            zoomBox[0] = zoomRect[0];
+            zoomBox[1] = zoomRect[1];
+            zoomBox[2] = zoomRect[2];
+            zoomBox[3] = zoomRect[3];
+            return sciZoom3D(iSubwinUID, zoomBox);
+        }
+        else
+        {
+            return SET_PROPERTY_ERROR;
+        }
     }
     else
     {
index 30f5a57..82edc60 100644 (file)
@@ -238,11 +238,13 @@ void* getchampdata(int iObjUID)
     getGraphicObjectProperty(iObjUID, __GO_DIRECTION_X__, jni_double_vector, (void **)&arrowDirectionsX);
     getGraphicObjectProperty(iObjUID, __GO_DIRECTION_Y__, jni_double_vector, (void **)&arrowDirectionsY);
 
-    addColVectorToReturnedList(tList, arrowBasesX, dimensions[0]);
-    addColVectorToReturnedList(tList, arrowBasesY, dimensions[1]);
-    addMatrixToReturnedList(tList, arrowDirectionsX, dimensions[0], dimensions[1]);
-    addMatrixToReturnedList(tList, arrowDirectionsY, dimensions[0], dimensions[1]);
-
+    if (dimensions)
+    {
+        addColVectorToReturnedList(tList, arrowBasesX, dimensions[0]);
+        addColVectorToReturnedList(tList, arrowBasesY, dimensions[1]);
+        addMatrixToReturnedList(tList, arrowDirectionsX, dimensions[0], dimensions[1]);
+        addMatrixToReturnedList(tList, arrowDirectionsY, dimensions[0], dimensions[1]);
+    }
     //destroyReturnedList(tList);
 
     return tList;
index 114d780..3ca3166 100644 (file)
@@ -58,6 +58,12 @@ int set_format_n_property(void* _pvCtx, int iObjUID, void* _pvData, int valueTyp
 
     getGraphicObjectProperty(iObjUID, __GO_FORMATN__, jni_string, (void **)&oldFormat);
 
+    if (!oldFormat)
+    {
+        Scierror(999, _("Could not retrieve format.\n"));
+        return SET_PROPERTY_ERROR;
+    }
+
     if (strcmp(format, oldFormat) == 0)
     {
         return SET_PROPERTY_SUCCEED;
index 0c84dcd..c7a696b 100644 (file)
@@ -994,6 +994,10 @@ static void updateXYDataBounds(int iSubwinUID, double rect[6])
         double * dataBounds = NULL;
         getGraphicObjectProperty(iSubwinUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **)&dataBounds);
 
+        if (!dataBounds)
+        {
+            return;
+        }
         rect[0] = Min(rect[0], dataBounds[0]);
         rect[1] = Max(rect[1], dataBounds[1]);
         rect[2] = Min(rect[2], dataBounds[2]);
@@ -1016,12 +1020,15 @@ static void updateXYZDataBounds(int iSubwinUID, double rect[6])
         double * dataBounds = NULL;
         getGraphicObjectProperty(iSubwinUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **)&dataBounds);
 
-        rect[0] = Min(rect[0], dataBounds[0]);
-        rect[1] = Max(rect[1], dataBounds[1]);
-        rect[2] = Min(rect[2], dataBounds[2]);
-        rect[3] = Max(rect[3], dataBounds[3]);
-        rect[4] = Min(rect[4], dataBounds[4]);
-        rect[5] = Max(rect[5], dataBounds[5]);
+        if (dataBounds)
+        {
+            rect[0] = Min(rect[0], dataBounds[0]);
+            rect[1] = Max(rect[1], dataBounds[1]);
+            rect[2] = Min(rect[2], dataBounds[2]);
+            rect[3] = Max(rect[3], dataBounds[3]);
+            rect[4] = Min(rect[4], dataBounds[4]);
+            rect[5] = Max(rect[5], dataBounds[5]);
+        }
     }
 
     setGraphicObjectProperty(iSubwinUID, __GO_DATA_BOUNDS__, rect, jni_double_vector, 6);