From 05e7cb6cfd0929046abe0ea44bab7a43d7f6d0d2 Mon Sep 17 00:00:00 2001 From: Christopher Peplin Date: Mon, 6 Jan 2014 15:40:35 -0500 Subject: Watch for an error when getting a bit field. --- src/bitfield/bitfield.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/bitfield/bitfield.c b/src/bitfield/bitfield.c index b244c9b1..795f0208 100644 --- a/src/bitfield/bitfield.c +++ b/src/bitfield/bitfield.c @@ -36,10 +36,13 @@ uint64_t get_bitfield(const uint8_t source[], const uint8_t source_length, ArrayOrBytes combined; memset(combined.bytes, 0, sizeof(combined.bytes)); - copy_bits_right_aligned(source, source_length, offset, bit_count, - combined.bytes, sizeof(combined.bytes)); - if(BYTE_ORDER == LITTLE_ENDIAN) { - combined.whole = __builtin_bswap64(combined.whole); + if(copy_bits_right_aligned(source, source_length, offset, bit_count, + combined.bytes, sizeof(combined.bytes))) { + if(BYTE_ORDER == LITTLE_ENDIAN) { + combined.whole = __builtin_bswap64(combined.whole); + } + } else { + // debug("couldn't copy enough bits from source") } return combined.whole; } -- cgit 1.2.3-korg