]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
common/command.c: Avoid NULL pointer use in cmd_auto_complete
authorAdam Lackorzynski <adam@l4re.org>
Fri, 15 May 2026 20:47:30 +0000 (22:47 +0200)
committerTom Rini <trini@konsulko.com>
Wed, 27 May 2026 23:59:16 +0000 (17:59 -0600)
Avoid using ps_prompt having a NULL pointer. For that, use the same
approach as in uboot_cli_readline().

Suggested-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Adam Lackorzynski <adam@l4re.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
common/command.c

index 0f9dd06d72be492823dc3c248f82990ebc422f36..eb2c2123534fd138a282da23b1c8063b5ec568bf 100644 (file)
@@ -367,11 +367,15 @@ int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp)
        int i, j, k, len, seplen, argc;
        int cnt;
        char last_char;
-#ifdef CONFIG_CMDLINE_PS_SUPPORT
-       const char *ps_prompt = env_get("PS1");
-#else
-       const char *ps_prompt = CONFIG_SYS_PROMPT;
-#endif
+       const char *ps_prompt;
+
+       if (IS_ENABLED(CONFIG_CMDLINE_PS_SUPPORT)) {
+               ps_prompt = env_get("PS1");
+
+               if (!ps_prompt)
+                       ps_prompt = CONFIG_SYS_PROMPT;
+       } else
+               ps_prompt = CONFIG_SYS_PROMPT;
 
        if (strcmp(prompt, ps_prompt) != 0)
                return 0;       /* not in normal console */