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 <shuicheng.lin@intel.com>
Signed-off-by: Dongqi Chen <chen.dq@neusoft.com>
This commit is contained in:
Dongqi Chen 2020-04-03 14:21:52 +08:00
parent b235d3c111
commit 456c255ea1
3 changed files with 10 additions and 5 deletions

View File

@ -20,7 +20,7 @@
#include "hwmonGroup.h" /* for ... bmc_get_grouptype */
#include "hwmonAlarm.h" /* for ... hwmonAlarm */
#define DELIMITER ((const char)',')
#define DELIMITER ((char)',')
/****************************************************************************
*

View File

@ -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

View File

@ -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 ) )
{