History

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); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Wenlin Kang committed 7 years ago

Commit ca976bf1 parent b5866271 file · +1 −1Browse files

Unified · Split

kernel/debug/kdb/kdb_io.c+1−1
@@ -446,7 +446,7 @@ poll_again: · 445 unmodified lines
446char *kdb_getstr(char *buffer, size_t bufsize, const char *prompt)446char *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);