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
446446 char *kdb_getstr(char *buffer, size_t bufsize, const char *prompt)
447447 {
448448 if (prompt && kdb_prompt_str != prompt)
449− strncpy(kdb_prompt_str, prompt, CMD_BUFLEN);
449+ strscpy(kdb_prompt_str, prompt, CMD_BUFLEN);
450450 kdb_printf(kdb_prompt_str);
451451 kdb_nextline = 1; /* Prompt and input resets line number */
452452 return kdb_read(buffer, bufsize);