From b82457eaa658153449d9eab728b19927311e88db Mon Sep 17 00:00:00 2001
From: Andrew Tridgell <tridge@samba.org>
Date: Sun, 27 Jul 2014 21:14:47 +1000
Subject: [PATCH] FollowMe: avoid integer underflow in mavlink txspace check

---
 FollowMe/simplegcs.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/FollowMe/simplegcs.cpp b/FollowMe/simplegcs.cpp
index 2c2c25fe0..8b3dafab5 100644
--- a/FollowMe/simplegcs.cpp
+++ b/FollowMe/simplegcs.cpp
@@ -65,8 +65,8 @@ void simplegcs_send_heartbeat(mavlink_channel_t chan) {
 
 bool simplegcs_try_send_statustext(mavlink_channel_t chan, const char *text, int len) {
 
-    int payload_space = comm_get_txspace(chan) - MAVLINK_NUM_NON_PAYLOAD_BYTES;
-    if (payload_space < MAVLINK_MSG_ID_STATUSTEXT_LEN) return false;
+    uint16_t txspace = comm_get_txspace(chan);
+    if (payload_space < MAVLINK_MSG_ID_STATUSTEXT_LEN+MAVLINK_NUM_NON_PAYLOAD_BYTES) return false;
 
     char statustext[50] = { 0 };
     if (len < 50) {
-- 
GitLab