Skip to content

Commit 59f4ce4

Browse files
committed
Fixed bug Arduino-IRremote#1214 8 bit overflow for variable containing rawlen.
1 parent 02c0e24 commit 59f4ce4

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/IRReceive.hpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -853,9 +853,9 @@ bool IRrecv::decodePulseDistanceWidthData(PulseDistanceWidthProtocolConstants *a
853853
/*
854854
* Static variables for the getBiphaselevel function
855855
*/
856-
uint_fast8_t sBiphaseDecodeRawbuffOffset; // Index into raw timing array
857-
uint16_t sBiphaseCurrentTimingIntervals; // 1, 2 or 3. Number of aBiphaseTimeUnit intervals of the current rawbuf[sBiphaseDecodeRawbuffOffset] timing.
858-
uint_fast8_t sBiphaseUsedTimingIntervals; // Number of already used intervals of sCurrentTimingIntervals.
856+
uint_fast8_t sBiphaseDecodeRawbuffOffset; // Index into raw timing array
857+
uint16_t sBiphaseCurrentTimingIntervals; // 1, 2 or 3. Number of aBiphaseTimeUnit intervals of the current rawbuf[sBiphaseDecodeRawbuffOffset] timing.
858+
uint_fast8_t sBiphaseUsedTimingIntervals; // Number of already used intervals of sCurrentTimingIntervals.
859859
uint16_t sBiphaseTimeUnit;
860860

861861
void IRrecv::initBiphaselevel(uint_fast8_t aRCDecodeRawbuffOffset, uint16_t aBiphaseTimeUnit) {
@@ -1281,7 +1281,12 @@ void IRrecv::printDistanceWidthTimingInfo(Print *aSerial, DistanceWidthTimingInf
12811281

12821282
uint32_t IRrecv::getTotalDurationOfRawData() {
12831283
uint16_t tSumOfDurationTicks = 0;
1284-
for (uint_fast8_t i = 1; i < decodedIRData.rawlen; i++) {
1284+
#if RAW_BUFFER_LENGTH <= 254 // saves around 75 bytes program memory and speeds up ISR
1285+
uint_fast8_t i;
1286+
#else
1287+
unsigned int i;
1288+
#endif
1289+
for (i = 1; i < decodedIRData.rawlen; i++) {
12851290
tSumOfDurationTicks += decodedIRData.rawDataPtr->rawbuf[i];
12861291
}
12871292
return tSumOfDurationTicks * (uint32_t) MICROS_PER_TICK;
@@ -1473,10 +1478,9 @@ void IRrecv::printIRResultMinimal(Print *aSerial) {
14731478
*/
14741479
void IRrecv::printIRResultRawFormatted(Print *aSerial, bool aOutputMicrosecondsInsteadOfTicks) {
14751480

1476-
uint8_t tRawlen = decodedIRData.rawlen;
14771481
// Print Raw data
14781482
aSerial->print(F("rawData["));
1479-
aSerial->print(tRawlen, DEC);
1483+
aSerial->print(decodedIRData.rawlen, DEC);
14801484
aSerial->println(F("]: "));
14811485

14821486
/*
@@ -1513,7 +1517,7 @@ void IRrecv::printIRResultRawFormatted(Print *aSerial, bool aOutputMicrosecondsI
15131517

15141518
uint32_t tDuration;
15151519
uint16_t tSumOfDurationTicks = 0;
1516-
for (i = 1; i < tRawlen; i++) {
1520+
for (i = 1; i < decodedIRData.rawlen; i++) {
15171521
auto tCurrentTicks = decodedIRData.rawDataPtr->rawbuf[i];
15181522
if (aOutputMicrosecondsInsteadOfTicks) {
15191523
tDuration = tCurrentTicks * MICROS_PER_TICK;
@@ -1540,7 +1544,7 @@ void IRrecv::printIRResultRawFormatted(Print *aSerial, bool aOutputMicrosecondsI
15401544
}
15411545
aSerial->print(tDuration, DEC);
15421546

1543-
if ((i & 1) && (i + 1) < tRawlen) {
1547+
if ((i & 1) && (i + 1) < decodedIRData.rawlen) {
15441548
aSerial->print(','); //',' not required for last one
15451549
}
15461550

0 commit comments

Comments
 (0)