Browse Source

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 5 years ago
committed by Damien George
parent
commit
dce590c29d
  1. 1
      lib/mp-readline/readline.c

1
lib/mp-readline/readline.c

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

Loading…
Cancel
Save