Watch for an error when getting a bit field.
authorChristopher Peplin <chris.peplin@rhubarbtech.com>
Mon, 6 Jan 2014 20:40:35 +0000 (15:40 -0500)
committerChristopher Peplin <chris.peplin@rhubarbtech.com>
Mon, 6 Jan 2014 20:40:35 +0000 (15:40 -0500)
src/bitfield/bitfield.c

index b244c9b..795f020 100644 (file)
@@ -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));
 
     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;
 }
     }
     return combined.whole;
 }