summaryrefslogtreecommitdiffstats
path: root/src/H5Znbit.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/H5Znbit.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/H5Znbit.c')
-rw-r--r--src/H5Znbit.c79
1 files changed, 37 insertions, 42 deletions
diff --git a/src/H5Znbit.c b/src/H5Znbit.c
index 6f090c3..8f785a2 100644
--- a/src/H5Znbit.c
+++ b/src/H5Znbit.c
@@ -138,7 +138,7 @@ H5Z_can_apply_nbit(hid_t UNUSED dcpl_id, hid_t type_id, hid_t UNUSED space_id)
FUNC_ENTER_NOAPI(H5Z_can_apply_nbit, FAIL)
/* Get datatype */
- if(NULL == (type = H5I_object_verify(type_id, H5I_DATATYPE)))
+ if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
/* Get datatype's class, for checking the "datatype class" */
@@ -742,7 +742,7 @@ H5Z_set_local_nbit(hid_t dcpl_id, hid_t type_id, hid_t space_id)
FUNC_ENTER_NOAPI(H5Z_set_local_nbit, FAIL)
/* Get datatype */
- if(NULL == (type = H5I_object_verify(type_id, H5I_DATATYPE)))
+ if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
/* Get datatype's class */
@@ -781,7 +781,7 @@ H5Z_set_local_nbit(hid_t dcpl_id, hid_t type_id, hid_t space_id)
HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "datatype needs too many nbit parameters")
/* Allocate memory space for cd_values[] */
- if(NULL == (cd_values = H5MM_malloc(cd_values_actual_nparms * sizeof(unsigned))))
+ if(NULL == (cd_values = (unsigned *)H5MM_malloc(cd_values_actual_nparms * sizeof(unsigned))))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for cd_values[]")
/* Get the plist structure */
@@ -862,81 +862,70 @@ done:
* Programmer: Xiaowen Wu
* Friday, January 21, 2005
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static size_t
H5Z_filter_nbit(unsigned flags, size_t cd_nelmts, const unsigned cd_values[],
size_t nbytes, size_t *buf_size, void **buf)
{
- size_t ret_value = 0; /* return value */
- size_t size_out = 0; /* size of output buffer */
- unsigned d_nelmts = 0; /* number of elements in the chunk */
- unsigned char *outbuf = NULL; /* pointer to new output buffer */
+ unsigned char *outbuf; /* pointer to new output buffer */
+ size_t size_out = 0; /* size of output buffer */
+ unsigned d_nelmts = 0; /* number of elements in the chunk */
+ size_t ret_value = 0; /* return value */
FUNC_ENTER_NOAPI(H5Z_filter_nbit, 0)
/* check arguments
* cd_values[0] stores actual number of parameters in cd_values[]
*/
- if (cd_nelmts!=cd_values[0])
+ if(cd_nelmts != cd_values[0])
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "invalid nbit aggression level")
/* check if need to do nbit compress or decompress
* cd_values[1] stores the flag if true indicating no need to compress
*/
- if (cd_values[1]) {
- ret_value = *buf_size;
- goto done;
- }
+ if(cd_values[1])
+ HGOTO_DONE(*buf_size)
/* copy a filter parameter to d_nelmts */
d_nelmts = cd_values[2];
/* input; decompress */
- if (flags & H5Z_FLAG_REVERSE) {
+ if(flags & H5Z_FLAG_REVERSE) {
size_out = d_nelmts * cd_values[4]; /* cd_values[4] stores datatype size */
/* allocate memory space for decompressed buffer */
- if(NULL==(outbuf = H5MM_malloc(size_out)))
+ if(NULL == (outbuf = (unsigned char *)H5MM_malloc(size_out)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed for nbit decompression")
/* decompress the buffer */
- H5Z_nbit_decompress(outbuf, d_nelmts, *buf, cd_values);
-
- *buf_size = size_out;
- ret_value = size_out;
- }
+ H5Z_nbit_decompress(outbuf, d_nelmts, (unsigned char *)*buf, cd_values);
+ } /* end if */
/* output; compress */
else {
- assert(nbytes == d_nelmts * cd_values[4]);
+ HDassert(nbytes == d_nelmts * cd_values[4]);
size_out = nbytes;
/* allocate memory space for compressed buffer */
- if(NULL==(outbuf = H5MM_malloc(size_out)))
+ if(NULL == (outbuf = (unsigned char *)H5MM_malloc(size_out)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed for nbit compression")
/* compress the buffer, size_out will be changed */
- H5Z_nbit_compress(*buf, d_nelmts, outbuf, &size_out, cd_values);
-
- *buf_size = nbytes;
- ret_value = size_out;
- }
+ H5Z_nbit_compress((unsigned char *)*buf, d_nelmts, outbuf, &size_out, cd_values);
+ } /* end else */
/* free the input buffer */
H5MM_xfree(*buf);
/* set return values */
*buf = outbuf;
- outbuf = NULL;
+ *buf_size = size_out;
+ ret_value = size_out;
done:
- if(outbuf)
- H5MM_xfree(outbuf);
FUNC_LEAVE_NOAPI(ret_value)
-}
+} /* end H5Z_filter_nbit() */
/* ======== Nbit Algorithm ===============================================
* assume one byte has 8 bit
@@ -946,14 +935,17 @@ done:
* atomic datatype is treated on byte basis
*/
-static void H5Z_nbit_next_byte(size_t *j, int *buf_len)
+static void
+H5Z_nbit_next_byte(size_t *j, int *buf_len)
{
++(*j);
*buf_len = 8 * sizeof(unsigned char);
}
-static void H5Z_nbit_decompress_one_byte(unsigned char *data, size_t data_offset, int k, int begin_i,
-int end_i, unsigned char *buffer, size_t *j, int *buf_len, parms_atomic p, int datatype_len)
+static void
+H5Z_nbit_decompress_one_byte(unsigned char *data, size_t data_offset, int k,
+ int begin_i, int end_i, unsigned char *buffer, size_t *j, int *buf_len,
+ parms_atomic p, int datatype_len)
{
int dat_len; /* dat_len is the number of bits to be copied in each data byte */
int uchar_offset;
@@ -995,7 +987,8 @@ int end_i, unsigned char *buffer, size_t *j, int *buf_len, parms_atomic p, int d
}
}
-static void H5Z_nbit_decompress_one_nooptype(unsigned char *data, size_t data_offset,
+static void
+H5Z_nbit_decompress_one_nooptype(unsigned char *data, size_t data_offset,
unsigned char *buffer, size_t *j, int *buf_len, unsigned size)
{
unsigned i; /* index */
@@ -1018,7 +1011,8 @@ static void H5Z_nbit_decompress_one_nooptype(unsigned char *data, size_t data_of
}
}
-static void H5Z_nbit_decompress_one_atomic(unsigned char *data, size_t data_offset,
+static void
+H5Z_nbit_decompress_one_atomic(unsigned char *data, size_t data_offset,
unsigned char *buffer, size_t *j, int *buf_len, parms_atomic p)
{
/* begin_i: the index of byte having first significant bit
@@ -1054,7 +1048,8 @@ static void H5Z_nbit_decompress_one_atomic(unsigned char *data, size_t data_offs
}
}
-static void H5Z_nbit_decompress_one_array(unsigned char *data, size_t data_offset,
+static void
+H5Z_nbit_decompress_one_array(unsigned char *data, size_t data_offset,
unsigned char *buffer, size_t *j, int *buf_len, const unsigned parms[])
{
unsigned i, total_size, base_class, base_size, n, begin_index;
@@ -1101,7 +1096,8 @@ static void H5Z_nbit_decompress_one_array(unsigned char *data, size_t data_offse
} /* end switch */
}
-static void H5Z_nbit_decompress_one_compound(unsigned char *data, size_t data_offset,
+static void
+H5Z_nbit_decompress_one_compound(unsigned char *data, size_t data_offset,
unsigned char *buffer, size_t *j, int *buf_len, const unsigned parms[])
{
unsigned i, nmembers, member_offset, member_class, size;
@@ -1139,7 +1135,8 @@ static void H5Z_nbit_decompress_one_compound(unsigned char *data, size_t data_of
}
}
-static void H5Z_nbit_decompress(unsigned char *data, unsigned d_nelmts, unsigned char *buffer,
+static void
+H5Z_nbit_decompress(unsigned char *data, unsigned d_nelmts, unsigned char *buffer,
const unsigned parms[])
{
/* i: index of data, j: index of buffer,
@@ -1410,7 +1407,5 @@ static void H5Z_nbit_compress(unsigned char *data, unsigned d_nelmts, unsigned c
}
break;
} /* end switch */
-
- *buffer_size = j + 1; /* sometimes is catually j, but to be safe */
}
#endif /* H5_HAVE_FILTER_NBIT */