Skip to content

Commit

Permalink
BUG: Integer underflow causes HUGE space() in sendGeneric() (#381)
Browse files Browse the repository at this point in the history
A mesgtime of zero (or less than the elapsed time to send a message) tickled
a bug in `sendGeneric()` due to the subtraction of two unsigned values resulting in a negative number.

This bug isn't catchable with our current unit test setup.
This was discovered by "on hardware" testing.
  • Loading branch information
crankyoldgit authored Dec 22, 2017
1 parent ef7d15f commit ac06877
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/IRsend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,12 @@ void IRsend::sendGeneric(const uint16_t headermark, const uint32_t headerspace,

// Footer
if (footermark) mark(footermark);
space(std::max(gap, mesgtime - usecs.elapsed()));
uint32_t elapsed = usecs.elapsed();
// Avoid potential unsigned integer underflow. e.g. when mesgtime is 0.
if (elapsed >= mesgtime)
space(gap);
else
space(std::max(gap, mesgtime - elapsed));
}
}

Expand Down

0 comments on commit ac06877

Please sign in to comment.