usart: stm32f0: stm32f1: do not null-terminate the buffer in console_read()

master
S.J.R. van Schaik 7 years ago
parent 4739b8f995
commit d1457e8be6
  1. 12
      source/platform/usart.c

@ -150,19 +150,14 @@ ssize_t console_read(struct console *console, char *buf, size_t n)
char *p = buf;
char c;
*buf = '\0';
while (console_peek(&c, console, 1) == 0) {
switch (c) {
case '\004':
if (buf < p)
goto out;
console_getc(&c, console);
return 0;
return p - buf;
default:
if (((size_t)p - (size_t)buf) >= n)
goto out;
return p - buf;
*p++ = c;
console_getc(&c, console);
@ -170,9 +165,6 @@ ssize_t console_read(struct console *console, char *buf, size_t n)
}
}
out:
*p = '\0';
return p - buf;
}

Loading…
Cancel
Save