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.
pull/5478/head
Yonatan Goldschmidt 2019-12-17 22:40:40 +02:00 zatwierdzone przez Damien George
rodzic df5c3bd976
commit dce590c29d
1 zmienionych plików z 1 dodań i 0 usunięć

Wyświetl plik

@ -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);
}