summaryrefslogtreecommitdiffstats
path: root/src/H5Spoint.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2010-01-15 03:05:59 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2010-01-15 03:05:59 (GMT)
commit066294e32131d1d81d326d35d67b0d753e8b8b56 (patch)
treeff8ac3f4d94edceeacf167486a8a9f7adcd01d63 /src/H5Spoint.c
parent22da4232a4693e3f0a4ee2f37053f85a28e885fd (diff)
downloadhdf5-066294e32131d1d81d326d35d67b0d753e8b8b56.zip
hdf5-066294e32131d1d81d326d35d67b0d753e8b8b56.tar.gz
hdf5-066294e32131d1d81d326d35d67b0d753e8b8b56.tar.bz2
[svn-r18109] Description:
Bring r18076-18096 from hdf5_1_8_coverity branch to trunk: r18076: Correct Coverity issue #1 by removing dead code r18077: Fix coverity item 142. When an error occurred while copying a linked list in H5S_point_copy, the library would not free the partially allocated list. Added code to free the list in this case. r18078: Correct Coverity issue #2 by removing impossible to reach code. r18079: Correct #3 by removing impossible to reach code. r18080: Correct Coverity issue #4 by removing impossible to reach code. r18081: fix coverity 26 , check (dblik->parent) before calls H5HF_man_iblock_detach(). r18082: Fixed coverity issues 321 and 316. 321: freed sm_buf in error handling to remove resource leak. Also set sm_buf to NULL after other instances in which it is freed to prevent double free. 316: initialized nmembs to 0. r18083: Correct Coverity issue #6 by removing debugging knob from error reporting code. r18084: Fix coverity item 269 + others. When a error occurred in a function using the h5tools error framework, the "past_catch" variable would not be set to true because that statement was before the label that goto jumped to. This could cause a failure in the cleanup section to go back to the start of the section, freeing variables twice, etc. Moved the label infront of past_catch=TRUE. r18085: fixed coverity #27, check if (heap) before use heap->obj.... r18086: fixed coverity #28, check curr_span not null before use it at if(curr_span && (io_bytes_left==0 || curr_seq>=maxseq)) r18087: Correct Coverity issue #7 by cleaning up correctly on error r18088: Correct Coverity #8 by removing unchanged variable checking code. r18089: Correct Coverity issue #9 - remove impossible to reach code. r18090: Correct Coverity issue #11 by removing impossible to reach code. Also clean up some minor style issues. r18091: Fix coverity items 314 and 318. Changed the improper assertion of the return value of a library function to a check, and a return(void) on failure. r18092: Fix coverity item 70. Changed the improper assertion of the return value of a library function to a check, and a return(void) on failure. r18093: Correct Coverity issue #12 by removing dead code. r18094: Correct Coverity issue #16 by removing debugging code. r18095: Fixed coverity issue # 271. Removed redundant checking and freeing of sm_buf1 and sm_buf2. r18096: Correct Coverity issue #17 by refactoring test to remove dead code. Also, removed previous "coverity" statements in comments, we'll review those issues again and see if we can figure them out, now that we have more experience with Coverity. Tested on: Mac OS X/32 10.6.2 (amazon)
Diffstat (limited to 'src/H5Spoint.c')
-rw-r--r--src/H5Spoint.c194
1 files changed, 106 insertions, 88 deletions
diff --git a/src/H5Spoint.c b/src/H5Spoint.c
index 84b427e..5f4c74d 100644
--- a/src/H5Spoint.c
+++ b/src/H5Spoint.c
@@ -119,11 +119,11 @@ H5FL_DEFINE_STATIC(H5S_pnt_list_t);
herr_t
H5S_point_iter_init(H5S_sel_iter_t *iter, const H5S_t *space)
{
- FUNC_ENTER_NOAPI_NOFUNC(H5S_point_iter_init);
+ FUNC_ENTER_NOAPI_NOFUNC(H5S_point_iter_init)
/* Check args */
- assert (space && H5S_SEL_POINTS==H5S_GET_SELECT_TYPE(space));
- assert (iter);
+ HDassert(space && H5S_SEL_POINTS==H5S_GET_SELECT_TYPE(space));
+ HDassert(iter);
/* Initialize the number of points to iterate over */
iter->elmt_left=space->select.num_elem;
@@ -134,7 +134,7 @@ H5S_point_iter_init(H5S_sel_iter_t *iter, const H5S_t *space)
/* Initialize type of selection iterator */
iter->type=H5S_sel_iter_point;
- FUNC_LEAVE_NOAPI(SUCCEED);
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5S_point_iter_init() */
@@ -156,16 +156,16 @@ H5S_point_iter_init(H5S_sel_iter_t *iter, const H5S_t *space)
static herr_t
H5S_point_iter_coords (const H5S_sel_iter_t *iter, hsize_t *coords)
{
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_iter_coords);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_iter_coords)
/* Check args */
- assert (iter);
- assert (coords);
+ HDassert(iter);
+ HDassert(coords);
/* Copy the offset of the current point */
HDmemcpy(coords,iter->u.pnt.curr->pnt,sizeof(hsize_t)*iter->rank);
- FUNC_LEAVE_NOAPI(SUCCEED);
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5S_point_iter_coords() */
@@ -187,18 +187,18 @@ H5S_point_iter_coords (const H5S_sel_iter_t *iter, hsize_t *coords)
static herr_t
H5S_point_iter_block (const H5S_sel_iter_t *iter, hsize_t *start, hsize_t *end)
{
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_iter_block);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_iter_block)
/* Check args */
- assert (iter);
- assert (start);
- assert (end);
+ HDassert(iter);
+ HDassert(start);
+ HDassert(end);
/* Copy the current point as a block */
HDmemcpy(start,iter->u.pnt.curr->pnt,sizeof(hsize_t)*iter->rank);
HDmemcpy(end,iter->u.pnt.curr->pnt,sizeof(hsize_t)*iter->rank);
- FUNC_LEAVE_NOAPI(SUCCEED);
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5S_point_iter_block() */
@@ -219,12 +219,12 @@ H5S_point_iter_block (const H5S_sel_iter_t *iter, hsize_t *start, hsize_t *end)
static hsize_t
H5S_point_iter_nelmts (const H5S_sel_iter_t *iter)
{
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_iter_nelmts);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_iter_nelmts)
/* Check args */
- assert (iter);
+ HDassert(iter);
- FUNC_LEAVE_NOAPI(iter->elmt_left);
+ FUNC_LEAVE_NOAPI(iter->elmt_left)
} /* H5S_point_iter_nelmts() */
@@ -250,17 +250,17 @@ H5S_point_iter_has_next_block(const H5S_sel_iter_t *iter)
{
htri_t ret_value=TRUE; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_iter_has_next_block);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_iter_has_next_block)
/* Check args */
- assert (iter);
+ HDassert(iter);
/* Check if there is another point in the list */
if(iter->u.pnt.curr->next==NULL)
HGOTO_DONE(FALSE);
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* H5S_point_iter_has_next_block() */
@@ -285,11 +285,11 @@ done:
static herr_t
H5S_point_iter_next(H5S_sel_iter_t *iter, size_t nelem)
{
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_iter_next);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_iter_next)
/* Check args */
- assert (iter);
- assert (nelem>0);
+ HDassert(iter);
+ HDassert(nelem>0);
/* Increment the iterator */
while(nelem>0) {
@@ -297,7 +297,7 @@ H5S_point_iter_next(H5S_sel_iter_t *iter, size_t nelem)
nelem--;
} /* end while */
- FUNC_LEAVE_NOAPI(SUCCEED);
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5S_point_iter_next() */
@@ -321,15 +321,15 @@ H5S_point_iter_next(H5S_sel_iter_t *iter, size_t nelem)
static herr_t
H5S_point_iter_next_block(H5S_sel_iter_t *iter)
{
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_iter_next_block);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_iter_next_block)
/* Check args */
- assert (iter);
+ HDassert(iter);
/* Increment the iterator */
iter->u.pnt.curr=iter->u.pnt.curr->next;
- FUNC_LEAVE_NOAPI(SUCCEED);
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5S_point_iter_next_block() */
@@ -353,12 +353,12 @@ H5S_point_iter_next_block(H5S_sel_iter_t *iter)
static herr_t
H5S_point_iter_release (H5S_sel_iter_t UNUSED * iter)
{
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_iter_release);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_iter_release)
/* Check args */
- assert (iter);
+ HDassert(iter);
- FUNC_LEAVE_NOAPI(SUCCEED);
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5S_point_iter_release() */
@@ -471,10 +471,10 @@ H5S_point_release (H5S_t *space)
{
H5S_pnt_node_t *curr, *next; /* Point selection nodes */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_release);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_release)
/* Check args */
- assert (space);
+ HDassert(space);
/* Delete all the nodes from the list */
curr=space->select.sel_info.pnt_lst->head;
@@ -492,7 +492,7 @@ H5S_point_release (H5S_t *space)
/* Reset the number of elements in the selection */
space->select.num_elem=0;
- FUNC_LEAVE_NOAPI(SUCCEED);
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5S_point_release() */
@@ -584,42 +584,60 @@ done:
static herr_t
H5S_point_copy(H5S_t *dst, const H5S_t *src, hbool_t UNUSED share_selection)
{
- H5S_pnt_node_t *curr, *new_node, *new_head; /* Point information nodes */
- herr_t ret_value=SUCCEED; /* return value */
+ H5S_pnt_node_t *curr, *new_node, *new_tail; /* Point information nodes */
+ herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT(H5S_point_copy);
+ FUNC_ENTER_NOAPI_NOINIT(H5S_point_copy)
- assert(src);
- assert(dst);
+ HDassert(src);
+ HDassert(dst);
/* Allocate room for the head of the point list */
- if((dst->select.sel_info.pnt_lst=H5FL_MALLOC(H5S_pnt_list_t))==NULL)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate point node");
+ if(NULL == (dst->select.sel_info.pnt_lst = H5FL_MALLOC(H5S_pnt_list_t)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate point node")
- curr=src->select.sel_info.pnt_lst->head;
- new_head=NULL;
- while(curr!=NULL) {
- /* Create each point */
+ curr = src->select.sel_info.pnt_lst->head;
+ new_tail = NULL;
+ while(curr) {
+ /* Create new point */
if(NULL == (new_node = H5FL_MALLOC(H5S_pnt_node_t)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate point node");
- if((new_node->pnt = (hsize_t *)H5MM_malloc(src->extent.rank*sizeof(hsize_t)))==NULL)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate coordinate information");
- HDmemcpy(new_node->pnt, curr->pnt, (src->extent.rank * sizeof(hsize_t)));
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate point node")
new_node->next = NULL;
+ if(NULL == (new_node->pnt = (hsize_t *)H5MM_malloc(src->extent.rank*sizeof(hsize_t)))) {
+ new_node = H5FL_FREE(H5S_pnt_node_t, new_node);
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate coordinate information")
+ } /* end if */
+
+ /* Copy over the point's coordinates */
+ HDmemcpy(new_node->pnt, curr->pnt, (src->extent.rank * sizeof(hsize_t)));
/* Keep the order the same when copying */
- if(new_head==NULL)
- new_head=dst->select.sel_info.pnt_lst->head=new_node;
+ if(NULL == new_tail)
+ new_tail = dst->select.sel_info.pnt_lst->head = new_node;
else {
- new_head->next=new_node;
- new_head=new_node;
+ new_tail->next = new_node;
+ new_tail = new_node;
} /* end else */
- curr=curr->next;
+ curr = curr->next;
} /* end while */
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ if(ret_value < 0) {
+ /* Traverse the (incomplete?) dst list, freeing all memory */
+ curr = dst->select.sel_info.pnt_lst->head;
+ while(curr) {
+ H5S_pnt_node_t *tmp_node = curr;
+
+ curr->pnt = H5MM_xfree(curr->pnt);
+ curr = curr->next;
+ tmp_node = H5FL_FREE(H5S_pnt_node_t, tmp_node);
+ } /* end while */
+
+ dst->select.sel_info.pnt_lst = H5FL_FREE(H5S_pnt_list_t, dst->select.sel_info.pnt_lst);
+ } /* end if */
+
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5S_point_copy() */
@@ -650,9 +668,9 @@ H5S_point_is_valid (const H5S_t *space)
unsigned u; /* Counter */
htri_t ret_value=TRUE; /* return value */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_is_valid);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_is_valid)
- assert(space);
+ HDassert(space);
/* Check each point to determine whether selection+offset is within extent */
curr = space->select.sel_info.pnt_lst->head;
@@ -670,7 +688,7 @@ H5S_point_is_valid (const H5S_t *space)
} /* end while */
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5S_point_is_valid() */
@@ -738,9 +756,9 @@ H5S_point_serial_size (const H5S_t *space)
H5S_pnt_node_t *curr; /* Point information nodes */
hssize_t ret_value; /* return value */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_serial_size);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_serial_size)
- assert(space);
+ HDassert(space);
/* Basic number of bytes required to serialize point selection:
* <type (4 bytes)> + <version (4 bytes)> + <padding (4 bytes)> +
@@ -756,7 +774,7 @@ H5S_point_serial_size (const H5S_t *space)
curr=curr->next;
} /* end while */
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5S_point_serial_size() */
@@ -787,9 +805,9 @@ H5S_point_serialize (const H5S_t *space, uint8_t *buf)
uint32_t len=0; /* number of bytes used */
unsigned u; /* local counting variable */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_serialize);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_serialize)
- assert(space);
+ HDassert(space);
/* Store the preamble information */
UINT32ENCODE(buf, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */
@@ -822,7 +840,7 @@ H5S_point_serialize (const H5S_t *space, uint8_t *buf)
/* Encode length */
UINT32ENCODE(lenp, (uint32_t)len); /* Store the length of the extra information */
- FUNC_LEAVE_NOAPI(SUCCEED);
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5S_point_serialize() */
@@ -1168,9 +1186,9 @@ H5S_point_is_contiguous(const H5S_t *space)
{
htri_t ret_value; /* return value */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_is_contiguous);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_is_contiguous)
- assert(space);
+ HDassert(space);
/* One point is definitely contiguous */
if(space->select.num_elem==1)
@@ -1178,7 +1196,7 @@ H5S_point_is_contiguous(const H5S_t *space)
else /* More than one point might be contiguous, but it's complex to check and we don't need it right now */
ret_value=FALSE;
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* H5S_point_is_contiguous() */
@@ -1205,9 +1223,9 @@ H5S_point_is_single(const H5S_t *space)
{
htri_t ret_value; /* return value */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_is_single);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_is_single)
- assert(space);
+ HDassert(space);
/* One point is definitely 'single' :-) */
if(space->select.num_elem==1)
@@ -1215,7 +1233,7 @@ H5S_point_is_single(const H5S_t *space)
else
ret_value=FALSE;
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* H5S_point_is_single() */
@@ -1245,10 +1263,10 @@ H5S_point_is_regular(const H5S_t *space)
{
htri_t ret_value; /* return value */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_is_regular);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_point_is_regular)
/* Check args */
- assert(space);
+ HDassert(space);
/* Only simple check for regular points for now... */
if(space->select.num_elem==1)
@@ -1256,7 +1274,7 @@ H5S_point_is_regular(const H5S_t *space)
else
ret_value=FALSE;
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* H5S_point_is_regular() */
@@ -1420,31 +1438,31 @@ H5S_point_get_seq_list(const H5S_t *space, unsigned flags, H5S_sel_iter_t *iter,
int i; /* Local index variable */
herr_t ret_value=SUCCEED; /* return value */
- FUNC_ENTER_NOAPI_NOINIT(H5S_point_get_seq_list);
+ FUNC_ENTER_NOAPI_NOINIT(H5S_point_get_seq_list)
/* Check args */
- assert(space);
- assert(iter);
- assert(maxseq>0);
- assert(maxelem>0);
- assert(nseq);
- assert(nelem);
- assert(off);
- assert(len);
+ HDassert(space);
+ HDassert(iter);
+ HDassert(maxseq > 0);
+ HDassert(maxelem > 0);
+ HDassert(nseq);
+ HDassert(nelem);
+ HDassert(off);
+ HDassert(len);
/* Choose the minimum number of bytes to sequence through */
- H5_CHECK_OVERFLOW(iter->elmt_left,hsize_t,size_t);
- start_io_left=io_left=(size_t)MIN(iter->elmt_left,maxelem);
+ H5_CHECK_OVERFLOW(iter->elmt_left, hsize_t, size_t);
+ start_io_left = io_left = (size_t)MIN(iter->elmt_left, maxelem);
/* Get the dataspace dimensions */
- if ((ndims=H5S_get_simple_extent_dims (space, dims, NULL))<0)
- HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to retrieve data space dimensions");
+ if((ndims = H5S_get_simple_extent_dims (space, dims, NULL)) < 0)
+ HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to retrieve data space dimensions")
/* Walk through the points in the selection, starting at the current */
/* location in the iterator */
- node=iter->u.pnt.curr;
- curr_seq=0;
- while(node!=NULL) {
+ node = iter->u.pnt.curr;
+ curr_seq = 0;
+ while(NULL != node) {
/* Compute the offset of each selected point in the buffer */
for(i = ndims - 1, acc = iter->elmt_size, loc = 0; i >= 0; i--) {
loc += (node->pnt[i] + space->select.offset[i]) * acc;
@@ -1507,6 +1525,6 @@ H5S_point_get_seq_list(const H5S_t *space, unsigned flags, H5S_sel_iter_t *iter,
*nelem=start_io_left-io_left;
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5S_point_get_seq_list() */