diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 1998-01-28 12:35:04 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 1998-01-28 12:35:04 (GMT) |
commit | faab4bbf1b0d17f85c0f2bf681844dc2bb369e99 (patch) | |
tree | 7701c343577057a7b1dc1adc46351b035a1f36ea /src/H5P.c | |
parent | 67bfd03657b6a8b08d7e898d4f3ae554cc2e8c5e (diff) | |
download | hdf5-faab4bbf1b0d17f85c0f2bf681844dc2bb369e99.zip hdf5-faab4bbf1b0d17f85c0f2bf681844dc2bb369e99.tar.gz hdf5-faab4bbf1b0d17f85c0f2bf681844dc2bb369e99.tar.bz2 |
[svn-r180] Seperated range checking of start, count & stride in H5Pset_hyperslab from
building hyperslab arrays so earlier hyperslab don't get blown away if the new
one is incorrect. Fixed fence-post error in range checking also.
Diffstat (limited to 'src/H5P.c')
-rw-r--r-- | src/H5P.c | 27 |
1 files changed, 14 insertions, 13 deletions
@@ -1007,23 +1007,28 @@ H5Pset_hyperslab(hid_t sid, const size_t *start, const size_t *count, const size /* Set up stride values for later use */ tmp_stride= H5MM_xmalloc(space->u.simple.rank*sizeof(size_t)); for (u=0; u<space->u.simple.rank; u++) { - tmp_stride[u] = stride ? stride[u] : 1; + tmp_stride[u] = stride ? stride[u] : 1; } + /* Range check arguments */ + for(u=0; u<space->u.simple.rank; u++) + { + if(start[u]<0 || start[u]>=space->u.simple.size[u]) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL,"hyperslab bounds out of range"); + if(start[u]+(SIGN(count[u])*(ABS(count[u])-1)*tmp_stride[u])<0 || start[u]+(SIGN(count[u])*(ABS(count[u])-1)*tmp_stride[u])>=space->u.simple.size[u]) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL,"hyperslab bounds out of range"); + } /* end for */ + /* Allocate space for the hyperslab information */ if (NULL==space->h.start) { - space->h.start= H5MM_xcalloc(space->u.simple.rank,sizeof(size_t)); - space->h.count= H5MM_xcalloc(space->u.simple.rank,sizeof(size_t)); - space->h.stride= H5MM_xcalloc(space->u.simple.rank,sizeof(size_t)); + space->h.start= H5MM_xcalloc(space->u.simple.rank,sizeof(size_t)); + space->h.count= H5MM_xcalloc(space->u.simple.rank,sizeof(size_t)); + space->h.stride= H5MM_xcalloc(space->u.simple.rank,sizeof(size_t)); } /* Build hyperslab */ for(u=0; u<space->u.simple.rank; u++) { - /* Range checking arguments */ - if(start[u]+(count[u]*tmp_stride[u])<=0 || start[u]+(count[u]*tmp_stride[u])>=space->u.simple.size[u]) - HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL,"hyperslab bounds out of range"); - /* copy "normalized" (i.e. strictly increasing) values for hyperslab parameters */ space->h.start[u]=MIN(start[u],start[u]+((ABS(count[u])-1)*tmp_stride[u])); space->h.count[u]=ABS(count[u]); @@ -1033,11 +1038,7 @@ H5Pset_hyperslab(hid_t sid, const size_t *start, const size_t *count, const size done: if (ret_value == FAIL) { /* Error condition cleanup */ - /* Free hyperslab arrays if we encounter an error */ - H5MM_xfree(space->h.start); - H5MM_xfree(space->h.count); - H5MM_xfree(space->h.stride); - space->hslab_def = FALSE; + } /* end if */ /* Normal function cleanup */ |