From 86b8ecb56ed66e2b604703d4fe47efbc6300cc36 Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Tue, 21 Mar 2017 09:53:14 -0400 Subject: [PATCH] adjust ManchesterEncode removed dead size check added a max size of 2k input bits (4k out) this shouldn't overload the array memory passed to it typically... --- common/lfdemod.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/common/lfdemod.c b/common/lfdemod.c index 5a1007fb..8307a890 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -308,15 +308,17 @@ uint32_t manchesterEncode2Bytes(uint16_t datain) { //by marshmellow //encode binary data into binary manchester -//NOTE: BitStream must have double the size available in memory to do the swap +//NOTE: BitStream must have triple the size of "size" available in memory to do the swap int ManchesterEncode(uint8_t *BitStream, size_t size) { - size_t modIdx=size, i=0; - if (size>modIdx) return -1; + //allow up to 4K out (means BitStream must be at least 2048+4096 to handle the swap) + size = (size>2048) ? 2048 : size; + size_t modIdx = size; + size_t i; for (size_t idx=0; idx < size; idx++){ BitStream[idx+modIdx++] = BitStream[idx]; BitStream[idx+modIdx++] = BitStream[idx]^1; } - for (; i<(size*2); i++){ + for (i=0; i<(size*2); i++){ BitStream[i] = BitStream[i+size]; } return i; -- 2.39.5