common/command.c: Avoid NULL pointer use in cmd_auto_complete
PATCH v2 1/1 common/command.c: Avoid NULL pointer use in cmd_auto_complete
Avoid using ps_prompt having a NULL pointer. For that, use the same approach as in uboot_cli_readline().
Suggested-by Simon Glass <[email protected]>
Signed-off-by Adam Lackorzynski <[email protected]>
--- common/command.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
common/command.c +9 -5
@@ -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 */
Signature · 1 line
2.53.0
Quoted 10 lines · Adam Lackorzynski
common/command.c: Avoid NULL pointer use incmd_auto_completeAvoid using
ps_prompthaving a NULL pointer. For that, use the same approach as inuboot_cli_readline().Suggested-by Simon Glass <[email protected]>Signed-off-by Adam Lackorzynski <[email protected]>
common/command.c| 14 +++++++++-----1 file changed, 9 insertions(+), 5 deletions(-)
Reviewed-by Simon Glass <[email protected]>
Quoted 4 lines · Adam Lackorzynski
Avoid using
ps_prompthaving a NULL pointer. For that, use the same approach as inuboot_cli_readline().
Applied to u-boot/next, thanks!
[1/1] common/command.c: Avoid NULL pointer use in cmd_auto_complete
commit: 8429766a7f08ebbc0e4bdd8bcc8939a6b3ebf251
Signature · 1 line
Tom