diff options
author | Wenlin Kang <wenlin.kang@windriver.com> | 2019-05-13 04:57:20 -0400 |
---|---|---|
committer | Daniel Thompson <daniel.thompson@linaro.org> | 2019-05-14 08:44:24 -0400 |
commit | ca976bfb3154c7bc67c4651ecd144fdf67ccaee7 (patch) | |
tree | c14984408a43c210a00b4a24334a52f36462fccc | |
parent | b586627e10f57ee3aa8f0cfab0d6f7dc4ae63760 (diff) |
kdb: Fix bound check compiler warning
The strncpy() function may leave the destination string buffer
unterminated, better use strscpy() instead.
This fixes the following warning with gcc 8.2:
kernel/debug/kdb/kdb_io.c: In function 'kdb_getstr':
kernel/debug/kdb/kdb_io.c:449:3: warning: 'strncpy' specified bound 256 equals destination size [-Wstringop-truncation]
strncpy(kdb_prompt_str, prompt, CMD_BUFLEN);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Wenlin Kang <wenlin.kang@windriver.com>
Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
-rw-r--r-- | kernel/debug/kdb/kdb_io.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 6a4b41484afe..3a5184eb6977 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c | |||
@@ -446,7 +446,7 @@ poll_again: | |||
446 | char *kdb_getstr(char *buffer, size_t bufsize, const char *prompt) | 446 | char *kdb_getstr(char *buffer, size_t bufsize, const char *prompt) |
447 | { | 447 | { |
448 | if (prompt && kdb_prompt_str != prompt) | 448 | if (prompt && kdb_prompt_str != prompt) |
449 | strncpy(kdb_prompt_str, prompt, CMD_BUFLEN); | 449 | strscpy(kdb_prompt_str, prompt, CMD_BUFLEN); |
450 | kdb_printf(kdb_prompt_str); | 450 | kdb_printf(kdb_prompt_str); |
451 | kdb_nextline = 1; /* Prompt and input resets line number */ | 451 | kdb_nextline = 1; /* Prompt and input resets line number */ |
452 | return kdb_read(buffer, bufsize); | 452 | return kdb_read(buffer, bufsize); |