]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
common: readline: Fix always true test
authorAndrew Goodbody <andrew.goodbody@linaro.org>
Wed, 25 Jun 2025 09:50:30 +0000 (10:50 +0100)
committerTom Rini <trini@konsulko.com>
Tue, 8 Jul 2025 21:35:49 +0000 (15:35 -0600)
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>
common/cli_readline.c

index 4e6797a1944eb8fb43352ee56c9ad05f9b40b034..0cb43e62000fbcaa77623c30fcd7e7cfd139a081 100644 (file)
@@ -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--;