Skip to content

Commit 5e6dc72

Browse files
authored
Merge pull request #77 from runger1101001/dev
Dev
2 parents 8246fe5 + a8a72b2 commit 5e6dc72

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/communication/Commander.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ void Commander::run(Stream& serial, char eol){
4747
received_chars[0] = 0;
4848
rec_cnt=0;
4949
}
50+
if (rec_cnt>=MAX_COMMAND_LENGTH) { // prevent buffer overrun if message is too long
51+
received_chars[0] = 0;
52+
rec_cnt=0;
53+
}
5054
}
5155

5256
com_port = tmp; // reset the instance to the internal value

src/communication/Commander.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#include "../common/lowpass_filter.h"
88
#include "commands.h"
99

10+
11+
#define MAX_COMMAND_LENGTH 20
12+
13+
1014
// Commander verbose display to the user type
1115
enum VerboseMode{
1216
nothing = 0, // display nothing - good for monitoring
@@ -178,7 +182,7 @@ class Commander
178182
int call_count = 0;//!< number callbacks that are subscribed
179183

180184
// helping variable for serial communication reading
181-
char received_chars[20] = {0}; //!< so far received user message - waiting for newline
185+
char received_chars[MAX_COMMAND_LENGTH] = {0}; //!< so far received user message - waiting for newline
182186
int rec_cnt = 0; //!< number of characters receives
183187

184188
// serial printing functions

0 commit comments

Comments
 (0)