From a9aea6c72692169d2ff6fdfe50b584d2b8ac24f7 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 4 Apr 2021 07:48:53 +0200 Subject: [PATCH] fix in nr demodulation , which fixes a crash in "lf em 4x05 info" --- common/lfdemod.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/common/lfdemod.c b/common/lfdemod.c index 221dba8d6..7972e8788 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -1720,8 +1720,13 @@ int askdemod_ext(uint8_t *bits, size_t *size, int *clk, int *invert, int maxErr, } else if (bits[i] <= low) { bits[bitnum++] = *invert ^ 1; } else if (i - lastBit >= *clk / 2 + tol) { - bits[bitnum] = bits[bitnum - 1]; - bitnum++; + if (bitnum > 0) { + bits[bitnum] = bits[bitnum - 1]; + bitnum++; + } else { + bits[bitnum] = 0; + bitnum++; + } } else { //in tolerance - looking for peak continue; }