Skip to content

Commit 74797a0

Browse files
authored
Fix decoding issue after buffer overflow. (#253)
The bug was tickled when the capture buffer overflowed. Though, it probably also manifests when are large or garbage message is captured, and writes data through out the buffer. When a smaller message comes in, the last entry which is typically the post message gap, is not cleared. This could caused the decoder(s) to get confused as they would be reading previous messages (or garbage) data. - Fixes Issue #246 - No unit tests for this bug is only tickled 'on device' due to interrupt handling. Our unit tests don't really cover that aspect.
1 parent 57a4ef0 commit 74797a0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/IRrecv.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void IRrecv::copyIrParams(irparams_t *dest) {
126126
char *cdest = (char *) dest; // NOLINT(readability/casting)
127127

128128
// Copy contents of src[] to dest[]
129-
for (uint16_t i=0; i < sizeof(irparams_t); i++)
129+
for (uint16_t i = 0; i < sizeof(irparams_t); i++)
130130
cdest[i] = csrc[i];
131131
}
132132

@@ -149,6 +149,16 @@ bool IRrecv::decode(decode_results *results, irparams_t *save) {
149149
return false;
150150
#endif
151151

152+
// Clear the entry we are currently pointing to when we got the timeout.
153+
// i.e. Stopped collecting IR data.
154+
// It's junk as we never wrote an entry to it and can only confuse decoding.
155+
// This is done here rather than logically the best place in read_timeout()
156+
// as it saves a few bytes of ICACHE_RAM as that routine is bound to an
157+
// interrupt. decode() is not stored in ICACHE_RAM.
158+
// Another better option would be to zero the entire irparams.rawbuf[] on
159+
// resume() but that is a much more expensive operation compare to this.
160+
irparams.rawbuf[irparams.rawlen] = 0;
161+
152162
bool resumed = false; // Flag indicating if we have resumed.
153163

154164
if (save == NULL) {

0 commit comments

Comments
 (0)