fix some malloc(0) in hdf5 module 04/10604/2
Antoine ELIAS [Mon, 25 Feb 2013 15:21:58 +0000 (16:21 +0100)]
Change-Id: I9646182a40c92b1d3d1b395b0dfa21fb3e7c9eba

scilab/modules/hdf5/sci_gateway/cpp/sci_import_from_hdf5.cpp
scilab/modules/hdf5/src/c/h5_readDataFromFile.c

index 63648e8..25049cd 100644 (file)
@@ -328,33 +328,36 @@ static bool import_double(int _iDatasetId, int _iItemPos, int *_piAddress, char
         return false;
     }
 
-    piDims = (int*)MALLOC(sizeof(int) * iDims);
-    iSize = getDatasetInfo(_iDatasetId, &iComplex, &iDims, piDims);
-
-    if (iDims == 2 && piDims[0] * piDims[1] != 0)
+    if (iDims != 0)
     {
-        if (iComplex)
-        {
-            pdblReal = (double *)MALLOC(iSize * sizeof(double));
-            pdblImg = (double *)MALLOC(iSize * sizeof(double));
-            iRet = readDoubleComplexMatrix(_iDatasetId, pdblReal, pdblImg);
-        }
-        else
+        piDims = (int*)MALLOC(sizeof(int) * iDims);
+        iSize = getDatasetInfo(_iDatasetId, &iComplex, &iDims, piDims);
+
+        if (iDims == 2 && piDims[0] * piDims[1] != 0)
         {
-            pdblReal = (double *)MALLOC(iSize * sizeof(double));
-            iRet = readDoubleMatrix(_iDatasetId, pdblReal);
-        }
+            if (iComplex)
+            {
+                pdblReal = (double *)MALLOC(iSize * sizeof(double));
+                pdblImg = (double *)MALLOC(iSize * sizeof(double));
+                iRet = readDoubleComplexMatrix(_iDatasetId, pdblReal, pdblImg);
+            }
+            else
+            {
+                pdblReal = (double *)MALLOC(iSize * sizeof(double));
+                iRet = readDoubleMatrix(_iDatasetId, pdblReal);
+            }
 
-        if (iRet)
+            if (iRet)
+            {
+                return false;
+            }
+        }
+        else if (iDims > 2)
         {
+            //hypermatrix
             return false;
         }
     }
-    else if (iDims > 2)
-    {
-        //hypermatrix
-        return false;
-    }
     else
     {
         /*bug 7224 : to close dataset */
index e9ec59a..eb742e6 100644 (file)
@@ -268,7 +268,7 @@ int getDatasetInfo(int _iDatasetId, int* _iComplex, int* _iDims, int* _piDims)
         return -1;
     }
 
-    if (_piDims != 0)
+    if (_piDims != 0 && *_iDims != 0)
     {
         int i = 0;
         hsize_t* dims = (hsize_t*)MALLOC(sizeof(hsize_t) * *_iDims);
@@ -287,6 +287,10 @@ int getDatasetInfo(int _iDatasetId, int* _iComplex, int* _iDims, int* _piDims)
         }
 
     }
+    else
+    {
+        iSize = 0;
+    }
 
     H5Sclose(space);
     return iSize;