From: Christopher Peplin Date: Mon, 6 Jan 2014 20:40:35 +0000 (-0500) Subject: Watch for an error when getting a bit field. X-Git-Tag: 5.0.2~277^2~3 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=commitdiff_plain;h=05e7cb6cfd0929046abe0ea44bab7a43d7f6d0d2;p=apps%2Fagl-service-can-low-level.git Watch for an error when getting a bit field. --- 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; }