summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgoldengrandpa <[email protected]>2023-06-09 09:09:50 +0800
committerGitHub <[email protected]>2023-06-09 09:09:50 +0800
commit1d239db59e58e0439d9f4fc61de44221bf5d9535 (patch)
treeec9f23e7d57ee595a88cc3903ab6aee7f57af4bd
parentf4294c6abc40ba4a1133e668414c02ea2a3b8d54 (diff)
[tty]修复多次scanf之后,导致丢数据的问题 (#7640)
-rw-r--r--components/drivers/tty/n_tty.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/components/drivers/tty/n_tty.c b/components/drivers/tty/n_tty.c
index 5ed7d6a6f8..8b6d1d089f 100644
--- a/components/drivers/tty/n_tty.c
+++ b/components/drivers/tty/n_tty.c
@@ -1436,14 +1436,15 @@ static int canon_copy_from_read_buf(struct tty_struct *tty, char *b, size_t nr)
size_t buf_size = RT_TTY_BUF - tail;
const void *from = read_buf_addr(ldata, tail);
+ size_t temp_n = n;
if (n > buf_size)
{
rt_memcpy(b, from, buf_size);
b += buf_size;
- n -= buf_size;
+ temp_n -= buf_size;
from = ldata->read_buf;
}
- rt_memcpy(b, from, n);
+ rt_memcpy(b, from, temp_n);
if (found)
{