From 456c255ea11b741ea91eca7f0f277f167488002f Mon Sep 17 00:00:00 2001 From: Dongqi Chen Date: Fri, 3 Apr 2020 14:21:52 +0800 Subject: [PATCH] Fix mtce build error with gcc-8.2.1 1.Remove 'const' in DELIMITER to fix "Werror=ignored-qualifiers" 2.Replace sprintf with snprintf, and add return value check for snprintf to fix "Werror=format-overflow" 3.Replace strncpy with snprintf to fix "Werror=stringop-truncation" Change-Id: Iecca021fc02df35a472a3f8aa04c9501998e2dba Story: 2007506 Task: 39279 Signed-off-by: Shuicheng Lin Signed-off-by: Dongqi Chen --- mtce/src/hwmon/hwmonSensor.cpp | 2 +- mtce/src/lmon/lmonUtil.cpp | 2 +- mtce/src/public/amon.c | 11 ++++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/mtce/src/hwmon/hwmonSensor.cpp b/mtce/src/hwmon/hwmonSensor.cpp index 5f4a2e50..475c7cd5 100644 --- a/mtce/src/hwmon/hwmonSensor.cpp +++ b/mtce/src/hwmon/hwmonSensor.cpp @@ -20,7 +20,7 @@ #include "hwmonGroup.h" /* for ... bmc_get_grouptype */ #include "hwmonAlarm.h" /* for ... hwmonAlarm */ -#define DELIMITER ((const char)',') +#define DELIMITER ((char)',') /**************************************************************************** * diff --git a/mtce/src/lmon/lmonUtil.cpp b/mtce/src/lmon/lmonUtil.cpp index eb0a798e..d0225e8d 100644 --- a/mtce/src/lmon/lmonUtil.cpp +++ b/mtce/src/lmon/lmonUtil.cpp @@ -332,7 +332,7 @@ int lmon_interfaces_init ( interface_ctrl_type * ptr, string physical_interface string line; while ( getline( finTwo, line ) ) { - strncpy(line_buf, line.c_str(), MAX_CHARS_ON_LINE); + snprintf(line_buf, sizeof(line_buf), "%s", line.c_str()); // the slave interfaces are listed as enXYYY enXYYY... // starting with the primary. Read all other slaves diff --git a/mtce/src/public/amon.c b/mtce/src/public/amon.c index b9146a2d..8c9d0c60 100644 --- a/mtce/src/public/amon.c +++ b/mtce/src/public/amon.c @@ -237,8 +237,9 @@ int active_monitor_dispatch ( void ) char str[AMON_MAX_LEN] ; unsigned int magic = 0 ; int seq ; + int ret ; - memset (str, 0, AMON_MAX_LEN ); + memset ( str, 0, sizeof(str) ); sscanf ( amon.rx_buf, "%s %8x %d", str, &magic, &seq ); /* Fault Insertion Controls */ @@ -256,8 +257,12 @@ int active_monitor_dispatch ( void ) magic = magic ^ -1 ; } - memset ( amon.tx_buf, 0 , AMON_MAX_LEN ); - sprintf( amon.tx_buf, "%s %8x %d%c", str, magic, seq, '\0' ); + memset ( amon.tx_buf, 0, sizeof(amon.tx_buf) ); + ret = snprintf( amon.tx_buf, sizeof(amon.tx_buf), "%s %8x %d", str, magic, seq ); + if ( ret >= (int)sizeof(amon.tx_buf) ) + { + syslog ( LOG_ERR, "amon.tx_buf is truncated\n"); + } if ( strcmp ( str, amon.name ) ) {