diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2003-11-08 15:32:53 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2003-11-08 15:32:53 (GMT) |
commit | 0497e80b5017f0292a3232cfec4e268f9776d137 (patch) | |
tree | adf245ba8f035a20cb91e688a2529e439674634c /src/H5D.c | |
parent | dd969f1eadfd2cd500f3f44415b85cfea7216794 (diff) | |
download | hdf5-0497e80b5017f0292a3232cfec4e268f9776d137.zip hdf5-0497e80b5017f0292a3232cfec4e268f9776d137.tar.gz hdf5-0497e80b5017f0292a3232cfec4e268f9776d137.tar.bz2 |
[svn-r7829] Purpose:
Bug fix & code cleanup
Description:
Allowing the library to call malloc with a size of 0 bytes causes problems
for some users, so we check for allocations of 0 bytes and disallow them now.
Cleaned up some code which could call malloc with 0 size.
Changed some code calling HDmalloc directly to call H5MM_malloc(), which
allows us to check for 0 sized allocations.
Platforms tested:
FreeBSD 4.9 (sleipnir)
too minor to require h5committest
Diffstat (limited to 'src/H5D.c')
-rw-r--r-- | src/H5D.c | 29 |
1 files changed, 16 insertions, 13 deletions
@@ -3419,19 +3419,22 @@ H5D_flush(const H5F_t *f, hid_t dxpl_id) if((num_dsets=H5F_get_obj_count(f, H5F_OBJ_DATASET))<0) HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to get dataset count") - H5_CHECK_OVERFLOW(num_dsets,int,size_t); - if(NULL==(id_list=H5MM_malloc((size_t)num_dsets*sizeof(hid_t)))) - HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to allocate memory for ID list") - if(H5F_get_obj_ids(f, H5F_OBJ_DATASET, -1, id_list)<0) - HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to get dataset ID list") - for(j=0; j<num_dsets; j++) { - if(NULL==(dataset=H5I_object_verify(id_list[j], H5I_DATASET))) - HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to get dataset object") - if(dataset->layout.type==H5D_COMPACT && dataset->layout.dirty) - if(H5O_modify(&(dataset->ent), H5O_LAYOUT_ID, 0, 0, 1, &(dataset->layout), dxpl_id)<0) - HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to update layout message") - dataset->layout.dirty = FALSE; - } + /* Check for something to do */ + if(num_dsets>0) { + H5_CHECK_OVERFLOW(num_dsets,int,size_t); + if(NULL==(id_list=H5MM_malloc((size_t)num_dsets*sizeof(hid_t)))) + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to allocate memory for ID list") + if(H5F_get_obj_ids(f, H5F_OBJ_DATASET, -1, id_list)<0) + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to get dataset ID list") + for(j=0; j<num_dsets; j++) { + if(NULL==(dataset=H5I_object_verify(id_list[j], H5I_DATASET))) + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to get dataset object") + if(dataset->layout.type==H5D_COMPACT && dataset->layout.dirty) + if(H5O_modify(&(dataset->ent), H5O_LAYOUT_ID, 0, 0, 1, &(dataset->layout), dxpl_id)<0) + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to update layout message") + dataset->layout.dirty = FALSE; + } + } /* end if */ done: if(id_list!=NULL) |