aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@7842ec3a-9562-4be5-9c5b-06ba18f2b668>2002-06-24 11:54:21 +0000
committertradke <tradke@7842ec3a-9562-4be5-9c5b-06ba18f2b668>2002-06-24 11:54:21 +0000
commit9969701758110acc19b891625f9277f6edec5c05 (patch)
tree56c4b8ff991e66d250b11b0114a63ba122a92206
parent6814775b11566b39eb80dcc226609cfd29b5729b (diff)
Fixed potential malloc() of zero bytes. Thanks to efence.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOHDF5Util/trunk@71 7842ec3a-9562-4be5-9c5b-06ba18f2b668
-rw-r--r--src/RecoverVar.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/RecoverVar.c b/src/RecoverVar.c
index 0e09cb8..fbe3db6 100644
--- a/src/RecoverVar.c
+++ b/src/RecoverVar.c
@@ -361,7 +361,7 @@ static int GetCommonAttributes (cGH *GH,
int groupindex;
hid_t datatype, dataspace;
hsize_t rank_stored, *dims_stored;
- int grouptype_stored, ndims_stored, numtimelevels_stored;
+ int grouptype_stored, numtimelevels_stored;
char *groupname, *msg;
char groupname_stored[128], fullvarname[128];
@@ -457,14 +457,17 @@ static int GetCommonAttributes (cGH *GH,
/* verify the dims and sizes */
HDF5_ERROR (dataspace = H5Dget_space (dataset));
- HDF5_ERROR (ndims_stored = H5Sget_simple_extent_ndims (dataspace));
- dims_stored = (hsize_t *) malloc (ndims_stored * sizeof (hsize_t));
- HDF5_ERROR (rank_stored = H5Sget_simple_extent_dims (dataspace,
- dims_stored, NULL));
+ HDF5_ERROR (rank_stored = H5Sget_simple_extent_ndims (dataspace));
/* scalars are stored as rank 0 in HDF5 but have rank 1 in Cactus */
if (rank_stored == 0)
{
rank_stored = 1;
+ dims_stored = NULL;
+ }
+ else
+ {
+ dims_stored = (hsize_t *) malloc (rank_stored * sizeof (hsize_t));
+ HDF5_ERROR (H5Sget_simple_extent_dims (dataspace, dims_stored, NULL));
}
HDF5_ERROR (H5Sclose (dataspace));
@@ -518,7 +521,10 @@ static int GetCommonAttributes (cGH *GH,
}
return (-1);
}
- free (dims_stored);
+ if (dims_stored)
+ {
+ free (dims_stored);
+ }
if (! CCTK_QueryGroupStorageI (GH, groupindex))
{
@@ -615,12 +621,15 @@ static int IOHDF5Util_RestoreGA (hid_t dataset, int vindex, int timelevel,
extras = ((pGA ***) pughGH->variables)[vindex][timelevel]->extras;
/* allocate memory for the biggest chunk */
- npoints = extras->rnpoints[rec_info->it_info->ioproc + 1];
- for (proc = 2; proc < rec_info->it_info->ioproc_every; proc++)
+ npoints = 1;
+ for (proc = rec_info->it_info->ioproc + 1;
+ proc < rec_info->it_info->ioproc + rec_info->it_info->ioproc_every &&
+ proc < CCTK_nProcs (rec_info->it_info->GH);
+ proc++)
{
- if (npoints < extras->rnpoints[rec_info->it_info->ioproc + proc])
+ if (npoints < extras->rnpoints[proc])
{
- npoints = extras->rnpoints[rec_info->it_info->ioproc + proc];
+ npoints = extras->rnpoints[proc];
}
}
buffer = malloc (npoints * rec_info->element_size);