summaryrefslogtreecommitdiff
path: root/common/cli_readline.c
diff options
context:
space:
mode:
authorAndrew Goodbody <andrew.goodbody@linaro.org>2025-06-25 10:50:30 +0100
committerTom Rini <trini@konsulko.com>2025-07-08 15:35:49 -0600
commitebb2c9e5500939cff5e812f54819174bbe6703df (patch)
treee886bd8d4c07bbfdd426901aaae01e888c6b2efb /common/cli_readline.c
parent3833600dbaa2d7008063f3127abf21be8f0fe6cd (diff)
common: readline: Fix always true test
The variable base is unsigned so >= 0 is always true. Fix this test so that it is actually useful. The fix prevents the code from causing a segfault in the case where Ctrl-w is pressed on a line consisting only of spaces. Fixes: dcc18ce0dbaf ("cli: Implement delete-word in cread_line()") Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
Diffstat (limited to 'common/cli_readline.c')
-rw-r--r--common/cli_readline.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/common/cli_readline.c b/common/cli_readline.c
index 4e6797a1944..0cb43e62000 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -332,8 +332,8 @@ int cread_line_process_ch(struct cli_line_state *cls, char ichar)
if (cls->num) {
uint base, wlen;
- for (base = cls->num - 1;
- base >= 0 && buf[base] == ' ';)
+ for (base = cls->num;
+ base > 0 && buf[base - 1] == ' ';)
base--;
for (; base > 0 && buf[base - 1] != ' ';)
base--;