From aa0d1433a98a4fb5610981c264acbaccee8df0b2 Mon Sep 17 00:00:00 2001 From: Erich Cordoba Date: Tue, 25 Jun 2019 16:00:40 -0500 Subject: [PATCH] Fix format-truncation warnings The following warnings are being addressed. - hbsUtil.cpp: The correct value for MAX_ENTRY_STR_LEN should be 13 this considering that values can be higher than 9999, the final space and the leading '\n'. - hwmonAlarm.cpp: As a result of a discussion with Eric Macdonald, he suggested to remove the entire case for FM_ALARM_STATE_CLEAR as the reason buffer is not used and thus, there's no need to store a string there. - pmonHdlr.cpp: A truncation warning was shown due to a possible usage of a unitialize buffer. The fix here is check by NULL. Change-Id: I3c80cce99b2f521f8c7a9de4ce2b6036960dfaf6 Signed-off-by: Erich Cordoba --- mtce/src/heartbeat/hbsUtil.cpp | 2 +- mtce/src/hwmon/hwmonAlarm.cpp | 10 +--------- mtce/src/pmon/pmonHdlr.cpp | 5 +++++ 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/mtce/src/heartbeat/hbsUtil.cpp b/mtce/src/heartbeat/hbsUtil.cpp index c4fbe4c7..ae2a81d3 100644 --- a/mtce/src/heartbeat/hbsUtil.cpp +++ b/mtce/src/heartbeat/hbsUtil.cpp @@ -163,7 +163,7 @@ void hbs_cluster_log ( string & hostname, if ( cluster.history[h].entries == MTCE_HBS_HISTORY_ENTRIES ) { #define MAX_CLUSTER_LINE_LEN 100 -#define MAX_ENTRY_STR_LEN 10 /* "9999:9999 " */ +#define MAX_ENTRY_STR_LEN 13 /* "9999:9999 " */ mtce_hbs_cluster_entry_type e = { 0, 0 } ; char str[MAX_CLUSTER_LINE_LEN] ; string line = ""; diff --git a/mtce/src/hwmon/hwmonAlarm.cpp b/mtce/src/hwmon/hwmonAlarm.cpp index 920b59bf..15f0f56d 100644 --- a/mtce/src/hwmon/hwmonAlarm.cpp +++ b/mtce/src/hwmon/hwmonAlarm.cpp @@ -257,15 +257,7 @@ int hwmon_alarm_util ( string & hostname, "%s is reporting a '%s' out-of-tolerance reading from the '%s' sensor", hostname.c_str(), _getSev_str (severity).c_str(), sub_entity.c_str()); - if ( state == FM_ALARM_STATE_CLEAR ) - { - snprintf(alarm.reason_text, FM_MAX_BUFFER_LENGTH, - "%s:%s alarm clear\n", - alarm.alarm_id, - alarm.entity_instance_id); - hostname_prefix_in_reason = false ; - } - else if ( state == FM_ALARM_STATE_MSG ) + if ( state == FM_ALARM_STATE_MSG ) { if ( severity == FM_ALARM_SEVERITY_WARNING ) { diff --git a/mtce/src/pmon/pmonHdlr.cpp b/mtce/src/pmon/pmonHdlr.cpp index f3bf72e2..5b0e065d 100644 --- a/mtce/src/pmon/pmonHdlr.cpp +++ b/mtce/src/pmon/pmonHdlr.cpp @@ -538,6 +538,11 @@ bool service_file_exists ( string service_filename, char * path_n_name_ptr, int max_len ) { + if ( path_n_name_ptr == NULL ) { + slog ("Path for service files search is null.\n"); + return false; + } + /* load the name of the service file */ snprintf ( path_n_name_ptr, max_len, "%s/%s", SYSTEMD_SERVICE_FILE_DIR1,