mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-17 04:03:33 +08:00
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
This commit is contained in:
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user