From fce798bc7a1862fbc78c5912c5d7d0a027f89692 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Tue, 13 Sep 2016 12:32:01 +1000 Subject: [PATCH] DataFlash: avoid integer underflow Thanks to mbelluzzo: https://github.com/ArduPilot/ardupilot/pull/4579/commits/f44b1b35560a70be1e984de796d5a0aff982eef8 --- libraries/DataFlash/DataFlash_File.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/DataFlash/DataFlash_File.cpp b/libraries/DataFlash/DataFlash_File.cpp index f0c61962e3..34539d66f5 100644 --- a/libraries/DataFlash/DataFlash_File.cpp +++ b/libraries/DataFlash/DataFlash_File.cpp @@ -207,7 +207,10 @@ void DataFlash_File::periodic_fullrate(const uint32_t now) uint16_t DataFlash_File::bufferspace_available() { uint16_t _head; - return (BUF_SPACE(_writebuf)) - critical_message_reserved_space(); + const uint16_t space = BUF_SPACE(_writebuf); + const uint16_t crit = critical_message_reserved_space(); + + return (space > crit) ? space - crit : 0; } // return true for CardInserted() if we successfully initialised