From b402c9697dc388412321ae0a07f60af6ac882394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Br=C3=BCnn?= Date: Sat, 15 Jun 2019 17:56:33 +0200 Subject: [PATCH] hardfault_log: fix NULL terminator truncation building "make omnibus_f4sd_default" with gcc 8.2.1 failes with: hardfault_log.c:315:7: error: 'strncat' specified bound 30 equals destination size gcc8 introduced -Wstringop-truncation, which will warn about NULL terminator truncation. This patch fixes two similar issues: - strncpy() makes no sense if we want to copy without NULL terminator - strncat() needs space to append the NULL terminator fixes #12283 --- src/systemcmds/hardfault_log/hardfault_log.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/systemcmds/hardfault_log/hardfault_log.c b/src/systemcmds/hardfault_log/hardfault_log.c index 04a98590ba..5a255840a7 100644 --- a/src/systemcmds/hardfault_log/hardfault_log.c +++ b/src/systemcmds/hardfault_log/hardfault_log.c @@ -172,7 +172,7 @@ static int format_fault_file_name(struct timespec *ts, char *buffer, unsigned in unsigned int plen = LOG_PATH_BASE_LEN; if (maxsz >= LOG_PATH_LEN) { - strncpy(buffer, LOG_PATH_BASE, plen); + memcpy(buffer, LOG_PATH_BASE, plen); maxsz -= plen; int rv = format_fault_time(TIME_FMT, ts, fmtbuff, arraySize(fmtbuff)); @@ -312,7 +312,7 @@ static int write_stack(bool inValid, int winsize, uint32_t wtopaddr, if (wtopaddr == topaddr) { strncpy(marker, "<-- ", sizeof(marker)); strncat(marker, sp_name, sizeof(marker) - 1); - strncat(marker, " top", sizeof(marker)); + strncat(marker, " top", sizeof(marker) - 1); } else if (wtopaddr == spaddr) { strncpy(marker, "<-- ", sizeof(marker)); @@ -321,7 +321,7 @@ static int write_stack(bool inValid, int winsize, uint32_t wtopaddr, } else if (wtopaddr == botaddr) { strncpy(marker, "<-- ", sizeof(marker)); strncat(marker, sp_name, sizeof(marker) - 1); - strncat(marker, " bottom", sizeof(marker)); + strncat(marker, " bottom", sizeof(marker) - 1); } else { marker[0] = '\0';