CentOS 8: fix sm-db and sm-common build error with gcc-8.2.1

replace strncpy with snprintf to ensure null terminator exist.
Add return value check for snprintf to avoid gcc-8.2.1 report
"Werror=format-truncation".

Test:
Pass sm-db and sm-common rpm package build

Story: 2007065
Task: 38070
Task: 38071

Change-Id: I53ead95bcef060f5382344b9f88bf110e23a89f5
Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com>
This commit is contained in:
Shuicheng Lin
2020-01-15 20:49:25 +08:00
parent 0b2adba145
commit f3fe0c74f1
2 changed files with 6 additions and 3 deletions

View File

@@ -68,7 +68,10 @@ static SmErrorT sm_node_utils_read_platform_config( const char key[],
if( 1 == sscanf( line, format, val ) )
{
val[sizeof(val)-1] = '\0';
snprintf( value, value_size, "%s", val );
if( snprintf( value, value_size, "%s", val ) >= value_size )
{
DPRINTFE("value is truncated.");
}
break;
}
}

View File

@@ -28,12 +28,12 @@ SmErrorT sm_db_configuration_convert( const char* col_name,
if( 0 == strcmp( SM_CONFIGURATION_TABLE_COLUMN_KEY,
col_name ) )
{
strncpy( record->key, col_data, SM_CONFIGURATION_KEY_MAX_CHAR );
snprintf( record->key, sizeof(record->key), "%s", col_data );
}
else if( 0 == strcmp( SM_CONFIGURATION_TABLE_COLUMN_VALUE,
col_name ) )
{
strncpy( record->value, col_data, SM_CONFIGURATION_VALUE_MAX_CHAR );
snprintf( record->value, sizeof(record->value), "%s", col_data );
}
else if( 0 == strcmp( SM_CONFIGURATION_TABLE_COLUMN_ID,
col_name ) )