summaryrefslogtreecommitdiffstats
path: root/src/H5Tbit.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2010-04-23 20:03:17 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2010-04-23 20:03:17 (GMT)
commit53a2317c8fe59d00c255e6f815fb307fc6d132f8 (patch)
tree627e5ac070dabc02f374de54ad93fb5f96c1ac99 /src/H5Tbit.c
parent43448681d8431f45bd48c4b2c183e5b21030ab8d (diff)
downloadhdf5-53a2317c8fe59d00c255e6f815fb307fc6d132f8.zip
hdf5-53a2317c8fe59d00c255e6f815fb307fc6d132f8.tar.gz
hdf5-53a2317c8fe59d00c255e6f815fb307fc6d132f8.tar.bz2
[svn-r18625] Description:
Checkpoint progress on Bz#1398 - strict aliasing issues. (Lots of compiler warnings & code cleanups also) Tested on: FreeBSD/32 6.3 (duty) in debug mode FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode Linux/32 2.6 (jam) w/PGI compilers, w/default API=1.8.x, w/C++ & FORTRAN, w/threadsafe, in debug mode Linux/64-amd64 2.6 (amani) w/Intel compilers, w/default API=1.6.x, w/C++ & FORTRAN, in production mode Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN, w/szip filter, in production mode Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN, in production mode Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in debug mode Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode Mac OS X/32 10.6.3 (amazon) in debug mode Mac OS X/32 10.6.3 (amazon) w/C++ & FORTRAN, w/threadsafe, in production mode
Diffstat (limited to 'src/H5Tbit.c')
-rw-r--r--src/H5Tbit.c512
1 files changed, 260 insertions, 252 deletions
diff --git a/src/H5Tbit.c b/src/H5Tbit.c
index a5340a6..2c289b0 100644
--- a/src/H5Tbit.c
+++ b/src/H5Tbit.c
@@ -24,9 +24,10 @@
#include "H5private.h" /*generic functions */
#include "H5Eprivate.h" /*error handling */
-#include "H5Iprivate.h" /*ID functions */
#include "H5MMprivate.h" /* Memory management */
#include "H5Tpkg.h" /*data-type functions */
+#include "H5WBprivate.h" /* Wrapped Buffers */
+
/*-------------------------------------------------------------------------
@@ -39,24 +40,22 @@
* Programmer: Robb Matzke
* Wednesday, June 10, 1998
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
void
-H5T_bit_copy (uint8_t *dst, size_t dst_offset, const uint8_t *src,
- size_t src_offset, size_t size)
+H5T_bit_copy(uint8_t *dst, size_t dst_offset, const uint8_t *src,
+ size_t src_offset, size_t size)
{
- int shift;
- unsigned mask_lo, mask_hi;
- int s_idx, d_idx;
+ unsigned shift;
+ unsigned mask_lo, mask_hi;
+ unsigned s_idx, d_idx;
/*
* Normalize the offset to be a byte number and a bit offset within that
* byte.
*/
- s_idx = (int)src_offset / 8;
- d_idx = (int)dst_offset / 8;
+ s_idx = src_offset / 8;
+ d_idx = dst_offset / 8;
src_offset %= 8;
dst_offset %= 8;
@@ -76,25 +75,27 @@ H5T_bit_copy (uint8_t *dst, size_t dst_offset, const uint8_t *src,
* ...+---------------+---------------+
* dst[d_idx+1] dst[d_idx]
*/
- while (src_offset && size>0) {
- unsigned nbits = (unsigned)MIN3 (size, 8-dst_offset, 8-src_offset);
- unsigned mask = (1<<nbits) - 1;
+ while(src_offset && size > 0) {
+ unsigned nbits = MIN3(size, 8 - dst_offset, 8 - src_offset);
+ unsigned mask = ((unsigned)1 << nbits) - 1;
- dst[d_idx] &= ~(mask<<dst_offset);
- dst[d_idx] |= ((src[s_idx]>>src_offset)&mask) << dst_offset;
+ dst[d_idx] &= (uint8_t)~(mask << dst_offset);
+ dst[d_idx] |= (uint8_t)(((src[s_idx] >> src_offset) & (uint8_t)mask) << dst_offset);
src_offset += nbits;
- if (src_offset>=8) {
+ if(src_offset >= 8) {
s_idx++;
src_offset %= 8;
- }
+ } /* end if */
+
dst_offset += nbits;
- if (dst_offset>=8) {
+ if(dst_offset >= 8) {
d_idx++;
dst_offset %= 8;
- }
+ } /* end if */
+
size -= nbits;
- }
+ } /* end while */
/*
* The middle bits. We are aligned on a source byte which needs to be
@@ -117,42 +118,44 @@ H5T_bit_copy (uint8_t *dst, size_t dst_offset, const uint8_t *src,
* bits). SHIFT is three since the source must be shifted right three bits
* to line up with the destination.
*/
- shift = (int)dst_offset;
- mask_lo = (1<<(8-shift))-1;
+ shift = dst_offset;
+ mask_lo = ((unsigned)1 << (8 - shift)) - 1;
mask_hi = (~mask_lo) & 0xff;
- for (/*void*/; size>8; size-=8, d_idx++, s_idx++) {
- if (shift) {
- dst[d_idx+0] &= ~(mask_lo<<shift);
- dst[d_idx+0] |= (src[s_idx] & mask_lo) << shift;
- dst[d_idx+1] &= ~(mask_hi>>(8-shift));
- dst[d_idx+1] |= (src[s_idx] & mask_hi) >> (8-shift);
- } else {
+ for(/*void*/; size > 8; size -= 8, d_idx++, s_idx++) {
+ if(shift) {
+ dst[d_idx + 0] &= (uint8_t)(~(mask_lo << shift));
+ dst[d_idx + 0] |= (uint8_t)((src[s_idx] & mask_lo) << shift);
+ dst[d_idx + 1] &= (uint8_t)(~(mask_hi >> (8 - shift)));
+ dst[d_idx + 1] |= (uint8_t)((src[s_idx] & mask_hi) >> (8 - shift));
+ } /* end if */
+ else
dst[d_idx] = src[s_idx];
- }
- }
+ } /* end for */
/* Finish up */
- while (size>0) {
- unsigned nbits = (unsigned)MIN3 (size, 8-dst_offset, 8-src_offset);
- unsigned mask = (1<<nbits) - 1;
+ while(size > 0) {
+ unsigned nbits = (unsigned)MIN3 (size, 8 - dst_offset, 8 - src_offset);
+ unsigned mask = ((unsigned)1 << nbits) - 1;
- dst[d_idx] &= ~(mask<<dst_offset);
- dst[d_idx] |= ((src[s_idx]>>src_offset)&mask) << dst_offset;
+ dst[d_idx] &= (uint8_t)(~(mask << dst_offset));
+ dst[d_idx] |= (uint8_t)(((src[s_idx] >> src_offset) & (uint8_t)mask) << dst_offset);
src_offset += nbits;
- if (src_offset>=8) {
+ if(src_offset >= 8) {
s_idx++;
src_offset %= 8;
- }
+ } /* end if */
+
dst_offset += nbits;
- if (dst_offset>=8) {
+ if(dst_offset >= 8) {
d_idx++;
dst_offset %= 8;
- }
+ } /* end if */
+
size -= nbits;
- }
-}
+ } /* end while */
+} /* end H5T_bit_copy() */
/*-------------------------------------------------------------------------
@@ -173,54 +176,64 @@ H5T_bit_copy (uint8_t *dst, size_t dst_offset, const uint8_t *src,
* Programmer: Raymond Lu
* Monday, April 12, 2004
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
-void
-H5T_bit_shift (uint8_t *buf, ssize_t shift_dist, size_t offset, size_t size)
+herr_t
+H5T_bit_shift(uint8_t *buf, ssize_t shift_dist, size_t offset, size_t size)
{
- uint8_t *tmp_buf;
+ uint8_t tmp_buf[512]; /* Temporary buffer */
+ H5WB_t *wb = NULL; /* Wrapped buffer for temporary buffer */
+ herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5T_bit_shift);
+ FUNC_ENTER_NOAPI(H5T_bit_shift, FAIL)
/* Sanity check */
- assert(buf);
- assert(size);
-
- if(!shift_dist)
- goto done;
- if((size_t)ABS(shift_dist) >= size) {
- H5T_bit_set(buf, offset, size, 0);
- goto done;
- }
-
- tmp_buf = (uint8_t*)H5MM_calloc(size/8+1);
- assert(tmp_buf);
-
- /* Shift vector by making copies */
- if(shift_dist > 0) { /* left shift */
- /* Copy part to be shifted to a temporary buffer */
- H5T_bit_copy(tmp_buf, (size_t)0, buf, offset, (size_t)(size - shift_dist));
-
- /* Copy it back to the original buffer */
- H5T_bit_copy(buf, offset + shift_dist, tmp_buf, (size_t)0, (size_t)(size - shift_dist));
-
- /* Zero-set the left part*/
- H5T_bit_set(buf, offset, (size_t)shift_dist, 0);
- } else { /* right shift */
- shift_dist = - shift_dist;
- H5T_bit_copy(tmp_buf, (size_t)0, buf, offset + shift_dist, (size_t)(size - shift_dist));
- H5T_bit_copy (buf, offset, tmp_buf, (size_t)0, (size_t)(size - shift_dist));
- H5T_bit_set(buf, offset + size - shift_dist, (size_t)shift_dist, 0);
- }
-
- /* Free temporary buffer */
- H5MM_xfree(tmp_buf);
+ HDassert(buf);
+ HDassert(size);
+
+ if(shift_dist) {
+ size_t abs_shift_dist = (size_t)ABS(shift_dist);
+
+ if(abs_shift_dist >= size)
+ H5T_bit_set(buf, offset, size, 0);
+ else {
+ size_t buf_size = (size / 8) + 1; /* Size of shift buffer needed */
+ uint8_t *shift_buf; /* Pointer to shift buffer */
+
+ /* Wrap the local buffer for serialized header info */
+ if(NULL == (wb = H5WB_wrap(tmp_buf, sizeof(tmp_buf))))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't wrap buffer")
+
+ /* Get a pointer to a buffer that's large enough */
+ if(NULL == (shift_buf = (uint8_t *)H5WB_actual(wb, buf_size)))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_NOSPACE, FAIL, "can't get actual buffer")
+
+ /* Shift vector by making copies */
+ if(shift_dist > 0) { /* left shift */
+ /* Copy part to be shifted to a temporary buffer */
+ H5T_bit_copy(shift_buf, (size_t)0, buf, offset, size - abs_shift_dist);
+
+ /* Copy it back to the original buffer */
+ H5T_bit_copy(buf, offset + abs_shift_dist, shift_buf, (size_t)0, size - abs_shift_dist);
+
+ /* Zero-set the left part*/
+ H5T_bit_set(buf, offset, abs_shift_dist, 0);
+ } /* end if */
+ else { /* right shift */
+ H5T_bit_copy(shift_buf, (size_t)0, buf, offset + abs_shift_dist, size - abs_shift_dist);
+ H5T_bit_copy(buf, offset, shift_buf, (size_t)0, size - abs_shift_dist);
+ H5T_bit_set(buf, offset + size - abs_shift_dist, abs_shift_dist, 0);
+ } /* end else */
+ } /* end else */
+ } /* end if */
done:
- FUNC_LEAVE_NOAPI_VOID
-}
+ /* Release resources */
+ if(wb && H5WB_unwrap(wb) < 0)
+ HDONE_ERROR(H5E_DATATYPE, H5E_CLOSEERROR, FAIL, "can't close wrapped buffer")
+
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5T_bit_shift() */
/*-------------------------------------------------------------------------
@@ -237,20 +250,18 @@ done:
* Programmer: Robb Matzke
* Tuesday, June 23, 1998
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
uint64_t
-H5T_bit_get_d (uint8_t *buf, size_t offset, size_t size)
+H5T_bit_get_d(uint8_t *buf, size_t offset, size_t size)
{
- uint64_t val=0;
+ uint64_t val = 0;
size_t i, hs;
uint64_t ret_value; /* Return value */
FUNC_ENTER_NOAPI_NOFUNC(H5T_bit_get_d)
- assert (8*sizeof(val)>=size);
+ HDassert(8 * sizeof(val) >= size);
H5T_bit_copy((uint8_t*)&val, (size_t)0, buf, offset, size);
switch(H5T_native_order_g) {
@@ -262,20 +273,23 @@ H5T_bit_get_d (uint8_t *buf, size_t offset, size_t size)
uint8_t tmp = ((uint8_t*)&val)[i];
((uint8_t*)&val)[i] = ((uint8_t*)&val)[sizeof(val) - (i + 1)];
((uint8_t*)&val)[sizeof(val) - (i + 1)] = tmp;
- }
+ } /* end for */
break;
+ case H5T_ORDER_ERROR:
+ case H5T_ORDER_VAX:
+ case H5T_ORDER_NONE:
default:
/* Unknown endianness. Bail out. */
HGOTO_DONE(UFAIL)
- }
+ } /* end switch */
/* Set return value */
ret_value = val;
done:
FUNC_LEAVE_NOAPI(ret_value)
-}
+} /* end H5T_bit_get_d() */
/*-------------------------------------------------------------------------
@@ -288,35 +302,36 @@ done:
* Programmer: Robb Matzke
* Wednesday, June 24, 1998
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
void
-H5T_bit_set_d (uint8_t *buf, size_t offset, size_t size, uint64_t val)
+H5T_bit_set_d(uint8_t *buf, size_t offset, size_t size, uint64_t val)
{
size_t i, hs;
- assert (8*sizeof(val)>=size);
+ HDassert(8 * sizeof(val) >= size);
- switch (H5T_native_order_g) {
+ switch(H5T_native_order_g) {
case H5T_ORDER_LE:
break;
case H5T_ORDER_BE:
- for (i=0, hs=sizeof(val)/2; i<hs; i++) {
- uint8_t tmp = ((uint8_t*)&val)[i];
- ((uint8_t*)&val)[i] = ((uint8_t*)&val)[sizeof(val)-(i+1)];
- ((uint8_t*)&val)[sizeof(val)-(i+1)] = tmp;
- }
+ for(i = 0, hs = sizeof(val) / 2; i < hs; i++) {
+ uint8_t tmp = ((uint8_t *)&val)[i];
+ ((uint8_t *)&val)[i] = ((uint8_t *)&val)[sizeof(val) - (i + 1)];
+ ((uint8_t *)&val)[sizeof(val) - (i + 1)] = tmp;
+ } /* end for */
break;
+ case H5T_ORDER_ERROR:
+ case H5T_ORDER_VAX:
+ case H5T_ORDER_NONE:
default:
- HDabort ();
- }
+ HDabort();
+ } /* end switch */
H5T_bit_copy(buf, offset, (uint8_t*)&val, (size_t)0, size);
-}
+} /* end H5T_bit_set_d() */
/*-------------------------------------------------------------------------
@@ -335,7 +350,7 @@ H5T_bit_set_d (uint8_t *buf, size_t offset, size_t size, uint64_t val)
*-------------------------------------------------------------------------
*/
void
-H5T_bit_set (uint8_t *buf, size_t offset, size_t size, hbool_t value)
+H5T_bit_set(uint8_t *buf, size_t offset, size_t size, hbool_t value)
{
int idx;
@@ -344,32 +359,31 @@ H5T_bit_set (uint8_t *buf, size_t offset, size_t size, hbool_t value)
offset %= 8;
/* The first partial byte */
- if (size && offset%8) {
- size_t nbits = MIN (size, 8-offset);
- unsigned mask = (1<<nbits)-1;
- if (value) {
- buf[idx++] |= mask << offset;
- } else {
- buf[idx++] &= ~(mask << offset);
- }
+ if(size && offset % 8) {
+ size_t nbits = MIN(size, 8 - offset);
+ unsigned mask = ((unsigned)1 << nbits) - 1;
+
+ if(value)
+ buf[idx++] |= (uint8_t)(mask << offset);
+ else
+ buf[idx++] &= (uint8_t)(~(mask << offset));
size -= nbits;
- }
+ } /* end if */
/* The middle bytes */
- while (size>=8) {
+ while(size >= 8) {
buf[idx++] = value ? 0xff : 0x00;
size -= 8;
- }
+ } /* end while */
/* The last partial byte */
- if (size) {
- if (value) {
- buf[idx] |= (1<<size)-1;
- } else {
- buf[idx] &= ~((1<<size)-1);
- }
- }
-}
+ if(size) {
+ if(value)
+ buf[idx] |= (uint8_t)(((unsigned)1 << size) - 1);
+ else
+ buf[idx] &= (uint8_t)(~(((unsigned)1 << size) - 1));
+ } /* end if */
+} /* end H5T_bit_set() */
/*-------------------------------------------------------------------------
@@ -390,8 +404,6 @@ H5T_bit_set (uint8_t *buf, size_t offset, size_t size, hbool_t value)
* Programmer: Robb Matzke
* Wednesday, June 10, 1998
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
ssize_t
@@ -401,10 +413,10 @@ H5T_bit_find(uint8_t *buf, size_t offset, size_t size, H5T_sdir_t direction,
ssize_t base = (ssize_t)offset;
ssize_t idx, i;
size_t iu;
- ssize_t ret_value=(-1); /* Return value */
+ ssize_t ret_value = (-1); /* Return value */
/* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5T_bit_find);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5T_bit_find)
/* Some functions call this with value=TRUE */
HDassert(TRUE == 1);
@@ -416,63 +428,64 @@ H5T_bit_find(uint8_t *buf, size_t offset, size_t size, H5T_sdir_t direction,
offset %= 8;
/* Beginning */
- if (offset) {
- for (iu=offset; iu<8 && size>0; iu++, size--) {
- if (value==(hbool_t)((buf[idx]>>iu) & 0x01))
- HGOTO_DONE(8*idx+(ssize_t)iu - base);
- }
+ if(offset) {
+ for(iu = offset; iu < 8 && size > 0; iu++, size--)
+ if(value == (hbool_t)((buf[idx] >> iu) & 0x01))
+ HGOTO_DONE(8 * idx + (ssize_t)iu - base);
+
offset = 0;
idx++;
- }
+ } /* end if */
+
/* Middle */
- while (size>=8) {
- if ((value?0x00:0xff)!=buf[idx]) {
- for (i=0; i<8; i++) {
- if (value==(hbool_t)((buf[idx]>>i) & 0x01))
- HGOTO_DONE(8*idx+i - base);
- }
- }
+ while(size >= 8) {
+ if((value ? 0x00 : 0xff) != buf[idx])
+ for(i = 0; i < 8; i++)
+ if(value == (hbool_t)((buf[idx] >> i) & 0x01))
+ HGOTO_DONE(8 * idx + i - base);
+
size -= 8;
idx++;
- }
+ } /* end while */
+
/* End */
- for (i=0; i<(ssize_t)size; i++) {
- if (value==(hbool_t)((buf[idx]>>i) & 0x01))
- HGOTO_DONE(8*idx+i - base);
- }
+ for(i = 0; i < (ssize_t)size; i++)
+ if(value == (hbool_t)((buf[idx] >> i) & 0x01))
+ HGOTO_DONE(8 * idx + i - base);
break;
case H5T_BIT_MSB:
/* Calculate index */
- idx = (ssize_t)((offset+size-1) / 8);
+ idx = (ssize_t)((offset + size - 1) / 8);
offset %= 8;
/* Beginning */
- if (size>8-offset && (offset+size)%8) {
- for (iu=(offset+size)%8; iu>0; --iu, --size) {
- if (value==(hbool_t)((buf[idx]>>(iu-1)) & 0x01))
- HGOTO_DONE(8*idx+(ssize_t)(iu-1) - base);
- }
+ if(size > 8 - offset && (offset + size) % 8) {
+ for(iu = (offset + size) % 8; iu > 0; --iu, --size)
+ if(value == (hbool_t)((buf[idx] >> (iu - 1)) & 0x01))
+ HGOTO_DONE(8 * idx + (ssize_t)(iu - 1) - base);
+
--idx;
- }
+ } /* end if */
+
/* Middle */
- while (size>=8) {
- if ((value?0x00:0xff)!=buf[idx]) {
- for (i=7; i>=0; --i) {
- if (value==(hbool_t)((buf[idx]>>i) & 0x01))
- HGOTO_DONE(8*idx+i - base);
- }
- }
+ while(size >= 8) {
+ if((value ? 0x00 : 0xff) != buf[idx]) {
+ for(i = 7; i >= 0; --i)
+ if(value == (hbool_t)((buf[idx] >> i) & 0x01))
+ HGOTO_DONE(8 * idx + i - base);
+ } /* end if */
+
size -= 8;
--idx;
- }
+ } /* end while */
+
/* End */
- if (size>0) {
- for (iu=offset+size; iu>offset; --iu) {
- if (value==(hbool_t)((buf[idx]>>(iu-1)) & 0x01))
- HGOTO_DONE(8*idx+(ssize_t)(iu-1) - base);
- }
- }
+ if(size > 0) {
+ for(iu = offset + size; iu > offset; --iu)
+ if(value == (hbool_t)((buf[idx] >> (iu - 1)) & 0x01))
+ HGOTO_DONE(8 * idx + (ssize_t)(iu - 1) - base);
+ } /* end if */
break;
default:
@@ -480,7 +493,7 @@ H5T_bit_find(uint8_t *buf, size_t offset, size_t size, H5T_sdir_t direction,
} /* end switch */
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5T_bit_find() */
@@ -498,8 +511,6 @@ done:
* Programmer: Robb Matzke
* Friday, June 26, 1998
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
htri_t
@@ -510,47 +521,50 @@ H5T_bit_inc(uint8_t *buf, size_t start, size_t size)
unsigned acc, mask;
/* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5T_bit_inc);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5T_bit_inc)
+
+ HDassert(buf);
- assert(buf);
start %= 8;
/* The first partial byte */
- if (start) {
- if (size+start<8) mask = (1<<size)-1;
- else mask = (1<<(8-start))-1;
- acc = (buf[idx]>>start) & mask;
+ if(start) {
+ if(size + start < 8)
+ mask = ((unsigned)1 << size) - 1;
+ else
+ mask = ((unsigned)1 << (8 - start)) - 1;
+ acc = ((unsigned)buf[idx] >> start) & mask;
acc += 1;
- carry = acc & (1<<MIN(size, 8-start));
- buf[idx] &= ~(mask<<start);
- buf[idx] |= (acc & mask) << start;
- size -= MIN(size, 8-start);
- start=0;
+ carry = acc & ((unsigned)1 << MIN(size, 8 - start));
+ buf[idx] &= (uint8_t)(~(mask << start));
+ buf[idx] |= (uint8_t)((acc & mask) << start);
+ size -= MIN(size, 8 - start);
+ start = 0;
idx++;
- }
+ } /* end if */
/* The middle */
- while (carry && size>=8) {
+ while(carry && size >= 8) {
acc = buf[idx];
acc += 1;
carry = acc & 0x100;
buf[idx] = acc & 0xff;
idx++;
size -= 8;
- }
+ } /* end while */
/* The last bits */
- if (carry && size>0) {
- mask = (1<<size)-1;
+ if(carry && size > 0) {
+ mask = ((unsigned)1 << size) - 1;
acc = buf[idx] & mask;
acc += 1;
- carry = acc & (1<<size);
- buf[idx] &= ~mask;
- buf[idx] |= acc & mask;
- }
+ carry = acc & ((unsigned)1 << size);
+ buf[idx] &= (uint8_t)(~mask);
+ buf[idx] |= (uint8_t)(acc & mask);
+ } /* end if */
- FUNC_LEAVE_NOAPI(carry ? TRUE : FALSE);
-}
+ FUNC_LEAVE_NOAPI(carry ? TRUE : FALSE)
+} /* end H5T_bit_inc() */
/*-------------------------------------------------------------------------
@@ -567,8 +581,6 @@ H5T_bit_inc(uint8_t *buf, size_t start, size_t size)
* Programmer: Raymond Lu
* March 17, 2004
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
htri_t
@@ -580,13 +592,13 @@ H5T_bit_dec(uint8_t *buf, size_t start, size_t size)
unsigned borrow = 0;
/* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5T_bit_dec);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5T_bit_dec)
- assert(buf);
- assert(size);
+ HDassert(buf);
+ HDassert(size);
/* The first partial byte */
- if ((size+start-1)/8 > idx) { /*bit sequence doesn't end in the same byte as starts*/
+ if((size + start - 1) / 8 > idx) { /*bit sequence doesn't end in the same byte as starts*/
/* Example: a sequence like 11000100 and start = 3. We substract 00001000 from
* it and get 10111100. If a sequence is 00000111, we do right shift for START
* bits and get 00000000. So we need to borrow from higher byte when we substract
@@ -597,42 +609,41 @@ H5T_bit_dec(uint8_t *buf, size_t start, size_t size)
buf[idx] -= 1 << pos;
idx++;
size -= (8 - pos);
- } else { /* bit sequence ends in the same byte as starts */
+
+ /* The middle bytes */
+ while(borrow && size >= 8) {
+ if(buf[idx])
+ borrow = 0;
+ buf[idx] -= 1;
+
+ idx++;
+ size -= 8;
+ } /* end while */
+
+ /* The last partial byte */
+ if(borrow && size > 0) {
+ /* Similar to the first byte case, where sequence ends in the same byte as starts */
+ tmp = buf[idx];
+ buf[idx] -= 1;
+ if((buf[idx] >> size) != tmp >> size)
+ buf[idx] += 1 << size;
+ } /* end if */
+ } /* end if */
+ else { /* bit sequence ends in the same byte as starts */
/* Example: a sequence like 11000100 and pos=3, size=3. We substract 00001000
* and get 10111100. A bit is borrowed from 6th bit(buf[idx]>>6=00000010, tmp>>6=00000011,
* not equal). We need to put this bit back by increment 1000000.
*/
tmp = buf[idx];
buf[idx] -= 1 << pos;
- if((buf[idx] >> (pos+size)) != tmp >> (pos+size)) {
- buf[idx] += 1 << (pos+size);
+ if((buf[idx] >> (pos + size)) != tmp >> (pos + size)) {
+ buf[idx] += 1 << (pos + size);
borrow = 1;
- }
- goto done;
- }
+ } /* end if */
+ } /* end else */
- /* The middle bytes */
- while (borrow && size>=8) {
- if(buf[idx])
- borrow = 0;
- buf[idx] -= 1;
-
- idx++;
- size -= 8;
- }
-
- /* The last partial byte */
- if (borrow && size>0) {
- /* Similar to the first byte case, where sequence ends in the same byte as starts */
- tmp = buf[idx];
- buf[idx] -= 1;
- if((buf[idx] >> size) != tmp >> size)
- buf[idx] += 1 << size;
- }
-
-done:
- FUNC_LEAVE_NOAPI(borrow ? TRUE : FALSE);
-}
+ FUNC_LEAVE_NOAPI(borrow ? TRUE : FALSE)
+} /* end H5T_bit_dec() */
/*-------------------------------------------------------------------------
@@ -646,8 +657,6 @@ done:
* Programmer: Raymond Lu
* March 19, 2004
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
void
@@ -660,38 +669,37 @@ H5T_bit_neg(uint8_t *buf, size_t start, size_t size)
/* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5T_bit_neg);
- assert(buf);
- assert(size);
+ HDassert(buf);
+ HDassert(size);
/* The first partial byte */
tmp = buf[idx];
- tmp = ~tmp;
+ tmp = (uint8_t)~tmp;
/* Simply copy the negated bit field back to the original byte */
- if((size+start-1)/8 > idx) { /*bit sequence doesn't end in the same byte as starts*/
- H5T_bit_copy (&(buf[idx]), pos, &tmp, pos, (8-pos));
+ if((size + start - 1) / 8 > idx) { /*bit sequence doesn't end in the same byte as starts*/
+ H5T_bit_copy(&(buf[idx]), pos, &tmp, pos, (8-pos));
idx++;
size -= (8 - pos);
- } else { /* bit sequence ends in the same byte as starts */
- H5T_bit_copy (&(buf[idx]), pos, &tmp, pos, size);
- goto done;
- }
-
- /* The middle bytes */
- while (size>=8) {
- buf[idx] = ~(buf[idx]);
- idx++;
- size -= 8;
- }
- /* The last partial byte */
- if(size > 0) {
- /* Similar to the first byte case, where sequence ends in the same byte as starts */
- tmp = buf[idx];
- tmp = ~tmp;
- H5T_bit_copy(&(buf[idx]), (size_t)0, &tmp, (size_t)0, size);
- }
+ /* The middle bytes */
+ while(size >= 8) {
+ buf[idx] = (uint8_t)~(buf[idx]);
+ idx++;
+ size -= 8;
+ } /* end while */
+
+ /* The last partial byte */
+ if(size > 0) {
+ /* Similar to the first byte case, where sequence ends in the same byte as starts */
+ tmp = buf[idx];
+ tmp = (uint8_t)~tmp;
+ H5T_bit_copy(&(buf[idx]), (size_t)0, &tmp, (size_t)0, size);
+ } /* end if */
+ } /* end if */
+ else /* bit sequence ends in the same byte as starts */
+ H5T_bit_copy(&(buf[idx]), pos, &tmp, pos, size);
-done:
FUNC_LEAVE_NOAPI_VOID
-}
+} /* end H5T_bit_neg() */
+