1
0
mirror of https://xff.cz/git/u-boot/ synced 2026-01-07 04:59:18 +01:00

cli: Terminate the string in cread_line_process_ch()

Rather than relying on the caller, terminate the string inside this
function. Do this each time we return, whether input is finished or
not. It is not needed when the input is aborted, since the string will
be discarded in that case.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2023-10-01 19:13:14 -06:00
committed by Tom Rini
parent e5509ce87b
commit 657e14da83

View File

@@ -263,6 +263,7 @@ int cread_line_process_ch(struct cli_line_state *cls, char ichar)
if (ichar == '\n') {
putc('\n');
buf[cls->eol_num] = '\0'; /* terminate the string */
return 0;
}
@@ -413,6 +414,12 @@ int cread_line_process_ch(struct cli_line_state *cls, char ichar)
break;
}
/*
* keep the string terminated...if we added a char at the end then we
* want a \0 after it
*/
buf[cls->eol_num] = '\0';
return -EAGAIN;
}
@@ -467,7 +474,6 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len,
break;
}
*len = cls->eol_num;
buf[cls->eol_num] = '\0'; /* lose the newline */
if (buf[0] && buf[0] != CREAD_HIST_CHAR)
cread_add_to_hist(buf);