Skip to content

Commit a841af4

Browse files
committed
Limit value range
1 parent 5ed638d commit a841af4

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

tfrog-motordriver/communication.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ int32_t atoi(char* buf)
144144
}
145145
buf++;
146146
}
147+
if (buf[0] == '-')
148+
{
149+
ret = -ret;
150+
}
147151
return ret;
148152
}
149153

@@ -1242,10 +1246,18 @@ int32_t extended_command_analyze(char* data)
12421246
}
12431247
else if (strstr(data, "$SETSOFTBRAKEMS") == data)
12441248
{
1245-
saved_param.soft_brake_ms = atoi(data + 15);
1246-
1247-
send(data);
1248-
send("\n00P\n\n");
1249+
const int32_t v = atoi(data + 15);
1250+
if (v < 0 || v > 10000)
1251+
{
1252+
send(data);
1253+
send("\n01Q\nOut of range\n\n");
1254+
}
1255+
else
1256+
{
1257+
saved_param.soft_brake_ms = v;
1258+
send(data);
1259+
send("\n00P\n\n");
1260+
}
12491261
}
12501262
else if (strstr(data, "$SETBUZZERLEVEL") == data)
12511263
{

0 commit comments

Comments
 (0)