lib/mp-readline: Add an assert() to catch buffer overflows.

During readline development, this function may receive bad `pos` values.
It's easier to understand the assert() failing error than to have a "stack
smashing detected" message.
This commit is contained in:
Yonatan Goldschmidt 2019-12-17 22:40:40 +02:00 committed by Damien George
parent df5c3bd976
commit dce590c29d
1 changed files with 1 additions and 0 deletions

View File

@ -74,6 +74,7 @@ STATIC void mp_hal_move_cursor_back(uint pos) {
// snprintf needs space for the terminating null character
int n = snprintf(&vt100_command[0], sizeof(vt100_command), "\x1b[%u", pos);
if (n > 0) {
assert((unsigned)n < sizeof(vt100_command));
vt100_command[n] = 'D'; // replace null char
mp_hal_stdout_tx_strn(vt100_command, n + 1);
}