From 9d9621ef0c2670b9813b36d74a665b04fe105cf0 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Tue, 21 Sep 2004 20:18:47 -0500 Subject: [svn-r9297] Purpose: Bug fix. Description: Code would attempt to Calloc with zero count when a simple expression that has no x term. That resulted in NULL for some platform (like AIX). That appeared as a failure treated as out of space. Solution: Checked if count is larger than 0 before making the calloc request. Platforms tested: Tested in copper (pp) where the failure appeared. Also in eirene as double check. No h5committest as the change is trivial. --- src/H5Ztrans.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/H5Ztrans.c b/src/H5Ztrans.c index 38e966f..f17319d 100644 --- a/src/H5Ztrans.c +++ b/src/H5Ztrans.c @@ -1685,9 +1685,13 @@ H5Z_xform_create(const char *expr) if(isalpha(expr[i])) count++; } - if((data_xform_prop->dat_val_pointers->ptr_dat_val = (void*) HDcalloc(count, sizeof(void*))) == NULL) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate memory for pointers in transform array") - + /* When there are no "x"'s in the equation (ie, simple transform case), + * we don't need to allocate any space since no array will have to be + * stored */ + if(count > 0) + if((data_xform_prop->dat_val_pointers->ptr_dat_val = (void*) HDcalloc(count, sizeof(void*))) == NULL) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate memory for pointers in transform array") + /* Initialize the num_ptrs field, which will be used to keep track of the number of copies * of the data we have for polynomial transforms */ data_xform_prop->dat_val_pointers->num_ptrs = 0; @@ -1807,8 +1811,9 @@ H5Z_xform_copy(H5Z_data_xform_t **data_xform_prop) if(isalpha(new_data_xform_prop->xform_exp[i])) count++; } - if((new_data_xform_prop->dat_val_pointers->ptr_dat_val = (void*) HDcalloc(count, sizeof(void*))) == NULL) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate memory for pointers in transform array") + if(count > 0) + if((new_data_xform_prop->dat_val_pointers->ptr_dat_val = (void*) HDcalloc(count, sizeof(void*))) == NULL) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate memory for pointers in transform array") /* Zero out num_pointers prior to H5Z_xform_cop_tree call; that call will increment it to the right amount */ new_data_xform_prop->dat_val_pointers->num_ptrs = 0; -- cgit v0.12