From 47209218accad43cabf88c671e12fc770988b762 Mon Sep 17 00:00:00 2001 From: Erich Cordoba Date: Mon, 20 Aug 2018 12:08:19 -0500 Subject: [PATCH] Avoid null check for reference in fm_snmp_util_gen_trap As C++ references cannot be NULL, new compilers optimizes the code assuming this condition. Therefore, in new compilers, from GCC 6 to 8 the fn_snmp_util_gen_trap will segfault trying to deference data.entity_instance_id as the if (&data != NULL) will be always optimized to be true. Turns out that the case where SFmAlarmDataT is expected to be NULL (or empty) is when the alarm type is WARM_START. So changing the if statement to look for WARM_START instead of checking the null reference seems to be a feasible solution. Story: 2003498 Task: 24775 Change-Id: Ica07ec8d7ad009e1048f014b0a6440c76de09eef Signed-off-by: Erich Cordoba --- fm-common/sources/fmSnmpUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fm-common/sources/fmSnmpUtils.cpp b/fm-common/sources/fmSnmpUtils.cpp index a88066a9..1086a947 100644 --- a/fm-common/sources/fmSnmpUtils.cpp +++ b/fm-common/sources/fmSnmpUtils.cpp @@ -181,7 +181,7 @@ bool fm_snmp_util_gen_trap(int type, SFmAlarmDataT &data) { res = getTrapDestList(); - if (&data != NULL) { + if (get_trap_objtype(type) != WARM_START) { eid.assign(data.entity_instance_id); std::string region_name = fm_db_util_get_region_name(); std::string sys_name = fm_db_util_get_system_name();