Re: [devel] [PATCH 2 of 3] amfnd: Fix all Cppcheck 1.77 issues [#2341] V2

2017-03-14 Thread A V Mahesh
Hi Gary,

Sorry I over looked it ,  will  see and fix it , while fixing other  Amf 
Dev review comments ( may be in V3 ).

-AVM

On 3/15/2017 11:01 AM, Gary Lee wrote:
> Hi Mahesh
>
> Did you see my proposed change?
>
> The ‘delete rec’ statement below will cause a double free, unless I’m 
> mistaken.
>
> Thanks
> Gary
>
>   void avnd_comp_pm_rec_del(AVND_CB *cb, AVND_COMP *comp, 
> AVND_COMP_PM_REC *rec)
>   {
>  -uint32_t rc = NCSCC_RC_SUCCESS;
>   SaUint64T pid = rec->pid;
>   TRACE_ENTER2("Comp '%s'", comp->name.c_str());
>   
>   /* delete the PM_REC from pm_list */
>  -rc = ncs_db_link_list_del(>pm_list, (uint8_t *)>pid);
>  +uint32_t rc = ncs_db_link_list_del(>pm_list, (uint8_t 
> *)>pid);
>   if (NCSCC_RC_SUCCESS != rc) {
>   LOG_NO("PM Rec doesn't exist in Comp '%s' of pid %llu", 
> comp->name.c_str(), pid);
>   }
>  -rec = nullptr;  /* rec is no more, dont use it */
>  +
>  +delete rec; /* rec is no more, dont use it */
>
>
>
> -Original Message-
> From: A V Mahesh 
> Date: Wednesday, 15 March 2017 at 3:30 pm
> To: , gary , 
> , 
> Cc: 
> Subject: [PATCH 2 of 3] amfnd: Fix all Cppcheck 1.77 issues [#2341] V2
>
>   src/amf/amfnd/amfnd.cc   |  15 +--
>   src/amf/amfnd/cbq.cc |   9 +++--
>   src/amf/amfnd/chc.cc |  29 +++--
>   src/amf/amfnd/clc.cc |  37 ++---
>   src/amf/amfnd/comp.cc|   8 +++-
>   src/amf/amfnd/compdb.cc  |  17 -
>   src/amf/amfnd/cpm.cc |  13 +
>   src/amf/amfnd/di.cc  |  35 +--
>   src/amf/amfnd/err.cc |  35 ++-
>   src/amf/amfnd/evt.cc |   3 +--
>   src/amf/amfnd/hcdb.cc|  13 +++--
>   src/amf/amfnd/imm.cc |   5 ++---
>   src/amf/amfnd/main.cc|  13 +
>   src/amf/amfnd/mds.cc |  20 +++-
>   src/amf/amfnd/pg.cc  |  33 +++--
>   src/amf/amfnd/proxy.cc   |   8 +++-
>   src/amf/amfnd/proxydb.cc |  17 +
>   src/amf/amfnd/sidb.cc|   3 +--
>   src/amf/amfnd/su.cc  |   3 +--
>   src/amf/amfnd/sudb.cc|   5 ++---
>   src/amf/amfnd/susm.cc|  19 +--
>   src/amf/amfnd/util.cc|   2 +-
>   22 files changed, 143 insertions(+), 199 deletions(-)
>  
>  
>  V2 Re-based changes on OpenSAF 5.2.RC1 tagged code.
>  [src/amf/amfnd/amfnd.cc:58] -> [src/amf/amfnd/amfnd.cc:63]: (style) 
> Variable 'del_cbk' is reassigned a value before the old one has been used.
>  [src/amf/amfnd/amfnd.cc:59] -> [src/amf/amfnd/amfnd.cc:65]: (style) 
> Variable 'o_comp' is reassigned a value before the old one has been used.
>  [src/amf/amfnd/amfnd.cc:191] -> [src/amf/amfnd/amfnd.cc:199]: (style) 
> Variable 'o_comp' is reassigned a value before the old one has been used.
>  [src/amf/amfnd/amfnd.cc:249] -> [src/amf/amfnd/amfnd.cc:250]: (style) 
> Variable 'res' is reassigned a value before the old one has been used.
>  [src/amf/amfnd/cbq.cc:441] -> [src/amf/amfnd/cbq.cc:442]: (style) 
> Variable 'temp_csi' is reassigned a value before the old one has been used.
>  [src/amf/amfnd/cbq.cc:734] -> [src/amf/amfnd/cbq.cc:748]: (style) 
> Variable 'rc' is reassigned a value before the old one has been used.
>  [src/amf/amfnd/cbq.cc:1132] -> [src/amf/amfnd/cbq.cc:1133]: (style) 
> Variable 'temp_csi' is reassigned a value before the old one has been used.
>  [src/amf/amfnd/chc.cc:842]: (style) The scope of the variable 'cbk_rec' 
> can be reduced.
>  [src/amf/amfnd/clc.cc:1402] -> [src/amf/amfnd/clc.cc:1408]: (warning, 
> inconclusive) Either the condition 'NCSCC_RC_SUCCESS!=rc&_rec' is 
> redundant or there is possible null pointer dereference: curr_rec.
>  [src/amf/amfnd/clc.cc:1403] -> [src/amf/amfnd/clc.cc:1408]: (warning, 
> inconclusive) Either the condition 'NCSCC_RC_SUCCESS!=rc&_rec' is 
> redundant or there is possible null pointer dereference: curr_rec.
>  [src/amf/amfnd/clc.cc:1404] -> [src/amf/amfnd/clc.cc:1408]: (warning, 
> inconclusive) Either the condition 'NCSCC_RC_SUCCESS!=rc&_rec' is 
> redundant or there is possible null pointer dereference: curr_rec.
>  [src/amf/amfnd/clc.cc:610] -> [src/amf/amfnd/clc.cc:616]: (style) 
> Variable 'clc_evt' is reassigned a value before the old one has been used.
>  [src/amf/amfnd/clc.cc:1708] -> [src/amf/amfnd/clc.cc:1712]: (style) 
> Variable 'rc' is reassigned a value before the old one has been used.
>  [src/amf/amfnd/clc.cc:1749] -> 

Re: [devel] [PATCH 2 of 3] amfnd: Fix all Cppcheck 1.77 issues [#2341] V2

2017-03-14 Thread Gary Lee
Hi Mahesh

Did you see my proposed change?

The ‘delete rec’ statement below will cause a double free, unless I’m mistaken.

Thanks
Gary

 void avnd_comp_pm_rec_del(AVND_CB *cb, AVND_COMP *comp, AVND_COMP_PM_REC 
*rec)
 {
-   uint32_t rc = NCSCC_RC_SUCCESS;
SaUint64T pid = rec->pid;
TRACE_ENTER2("Comp '%s'", comp->name.c_str());
 
/* delete the PM_REC from pm_list */
-   rc = ncs_db_link_list_del(>pm_list, (uint8_t *)>pid);
+   uint32_t rc = ncs_db_link_list_del(>pm_list, (uint8_t 
*)>pid);
if (NCSCC_RC_SUCCESS != rc) {
LOG_NO("PM Rec doesn't exist in Comp '%s' of pid %llu", 
comp->name.c_str(), pid);
}
-   rec = nullptr;  /* rec is no more, dont use it */
+
+   delete rec; /* rec is no more, dont use it */



-Original Message-
From: A V Mahesh 
Date: Wednesday, 15 March 2017 at 3:30 pm
To: , gary , 
, 
Cc: 
Subject: [PATCH 2 of 3] amfnd: Fix all Cppcheck 1.77 issues [#2341] V2

 src/amf/amfnd/amfnd.cc   |  15 +--
 src/amf/amfnd/cbq.cc |   9 +++--
 src/amf/amfnd/chc.cc |  29 +++--
 src/amf/amfnd/clc.cc |  37 ++---
 src/amf/amfnd/comp.cc|   8 +++-
 src/amf/amfnd/compdb.cc  |  17 -
 src/amf/amfnd/cpm.cc |  13 +
 src/amf/amfnd/di.cc  |  35 +--
 src/amf/amfnd/err.cc |  35 ++-
 src/amf/amfnd/evt.cc |   3 +--
 src/amf/amfnd/hcdb.cc|  13 +++--
 src/amf/amfnd/imm.cc |   5 ++---
 src/amf/amfnd/main.cc|  13 +
 src/amf/amfnd/mds.cc |  20 +++-
 src/amf/amfnd/pg.cc  |  33 +++--
 src/amf/amfnd/proxy.cc   |   8 +++-
 src/amf/amfnd/proxydb.cc |  17 +
 src/amf/amfnd/sidb.cc|   3 +--
 src/amf/amfnd/su.cc  |   3 +--
 src/amf/amfnd/sudb.cc|   5 ++---
 src/amf/amfnd/susm.cc|  19 +--
 src/amf/amfnd/util.cc|   2 +-
 22 files changed, 143 insertions(+), 199 deletions(-)


V2 Re-based changes on OpenSAF 5.2.RC1 tagged code.
[src/amf/amfnd/amfnd.cc:58] -> [src/amf/amfnd/amfnd.cc:63]: (style) 
Variable 'del_cbk' is reassigned a value before the old one has been used.
[src/amf/amfnd/amfnd.cc:59] -> [src/amf/amfnd/amfnd.cc:65]: (style) 
Variable 'o_comp' is reassigned a value before the old one has been used.
[src/amf/amfnd/amfnd.cc:191] -> [src/amf/amfnd/amfnd.cc:199]: (style) 
Variable 'o_comp' is reassigned a value before the old one has been used.
[src/amf/amfnd/amfnd.cc:249] -> [src/amf/amfnd/amfnd.cc:250]: (style) 
Variable 'res' is reassigned a value before the old one has been used.
[src/amf/amfnd/cbq.cc:441] -> [src/amf/amfnd/cbq.cc:442]: (style) Variable 
'temp_csi' is reassigned a value before the old one has been used.
[src/amf/amfnd/cbq.cc:734] -> [src/amf/amfnd/cbq.cc:748]: (style) Variable 
'rc' is reassigned a value before the old one has been used.
[src/amf/amfnd/cbq.cc:1132] -> [src/amf/amfnd/cbq.cc:1133]: (style) 
Variable 'temp_csi' is reassigned a value before the old one has been used.
[src/amf/amfnd/chc.cc:842]: (style) The scope of the variable 'cbk_rec' can 
be reduced.
[src/amf/amfnd/clc.cc:1402] -> [src/amf/amfnd/clc.cc:1408]: (warning, 
inconclusive) Either the condition 'NCSCC_RC_SUCCESS!=rc&_rec' is 
redundant or there is possible null pointer dereference: curr_rec.
[src/amf/amfnd/clc.cc:1403] -> [src/amf/amfnd/clc.cc:1408]: (warning, 
inconclusive) Either the condition 'NCSCC_RC_SUCCESS!=rc&_rec' is 
redundant or there is possible null pointer dereference: curr_rec.
[src/amf/amfnd/clc.cc:1404] -> [src/amf/amfnd/clc.cc:1408]: (warning, 
inconclusive) Either the condition 'NCSCC_RC_SUCCESS!=rc&_rec' is 
redundant or there is possible null pointer dereference: curr_rec.
[src/amf/amfnd/clc.cc:610] -> [src/amf/amfnd/clc.cc:616]: (style) Variable 
'clc_evt' is reassigned a value before the old one has been used.
[src/amf/amfnd/clc.cc:1708] -> [src/amf/amfnd/clc.cc:1712]: (style) 
Variable 'rc' is reassigned a value before the old one has been used.
[src/amf/amfnd/clc.cc:1749] -> [src/amf/amfnd/clc.cc:1753]: (style) 
Variable 'rc' is reassigned a value before the old one has been used.
[src/amf/amfnd/clc.cc:1951] -> [src/amf/amfnd/clc.cc:1955]: (style) 
Variable 'rc' is reassigned a value before the old one has been used.
[src/amf/amfnd/clc.cc:2370] -> [src/amf/amfnd/clc.cc:2376]: (style) 
Variable 'csi' is reassigned a value before the old one has been used.
[src/amf/amfnd/clc.cc:3052] -> [src/amf/amfnd/clc.cc:3053]: (style) 

[devel] [PATCH 2 of 3] amfnd: Fix all Cppcheck 1.77 issues [#2341] V2

2017-03-14 Thread A V Mahesh
 src/amf/amfnd/amfnd.cc   |  15 +--
 src/amf/amfnd/cbq.cc |   9 +++--
 src/amf/amfnd/chc.cc |  29 +++--
 src/amf/amfnd/clc.cc |  37 ++---
 src/amf/amfnd/comp.cc|   8 +++-
 src/amf/amfnd/compdb.cc  |  17 -
 src/amf/amfnd/cpm.cc |  13 +
 src/amf/amfnd/di.cc  |  35 +--
 src/amf/amfnd/err.cc |  35 ++-
 src/amf/amfnd/evt.cc |   3 +--
 src/amf/amfnd/hcdb.cc|  13 +++--
 src/amf/amfnd/imm.cc |   5 ++---
 src/amf/amfnd/main.cc|  13 +
 src/amf/amfnd/mds.cc |  20 +++-
 src/amf/amfnd/pg.cc  |  33 +++--
 src/amf/amfnd/proxy.cc   |   8 +++-
 src/amf/amfnd/proxydb.cc |  17 +
 src/amf/amfnd/sidb.cc|   3 +--
 src/amf/amfnd/su.cc  |   3 +--
 src/amf/amfnd/sudb.cc|   5 ++---
 src/amf/amfnd/susm.cc|  19 +--
 src/amf/amfnd/util.cc|   2 +-
 22 files changed, 143 insertions(+), 199 deletions(-)


V2 Re-based changes on OpenSAF 5.2.RC1 tagged code.
[src/amf/amfnd/amfnd.cc:58] -> [src/amf/amfnd/amfnd.cc:63]: (style) Variable 
'del_cbk' is reassigned a value before the old one has been used.
[src/amf/amfnd/amfnd.cc:59] -> [src/amf/amfnd/amfnd.cc:65]: (style) Variable 
'o_comp' is reassigned a value before the old one has been used.
[src/amf/amfnd/amfnd.cc:191] -> [src/amf/amfnd/amfnd.cc:199]: (style) Variable 
'o_comp' is reassigned a value before the old one has been used.
[src/amf/amfnd/amfnd.cc:249] -> [src/amf/amfnd/amfnd.cc:250]: (style) Variable 
'res' is reassigned a value before the old one has been used.
[src/amf/amfnd/cbq.cc:441] -> [src/amf/amfnd/cbq.cc:442]: (style) Variable 
'temp_csi' is reassigned a value before the old one has been used.
[src/amf/amfnd/cbq.cc:734] -> [src/amf/amfnd/cbq.cc:748]: (style) Variable 'rc' 
is reassigned a value before the old one has been used.
[src/amf/amfnd/cbq.cc:1132] -> [src/amf/amfnd/cbq.cc:1133]: (style) Variable 
'temp_csi' is reassigned a value before the old one has been used.
[src/amf/amfnd/chc.cc:842]: (style) The scope of the variable 'cbk_rec' can be 
reduced.
[src/amf/amfnd/clc.cc:1402] -> [src/amf/amfnd/clc.cc:1408]: (warning, 
inconclusive) Either the condition 'NCSCC_RC_SUCCESS!=rc&_rec' is 
redundant or there is possible null pointer dereference: curr_rec.
[src/amf/amfnd/clc.cc:1403] -> [src/amf/amfnd/clc.cc:1408]: (warning, 
inconclusive) Either the condition 'NCSCC_RC_SUCCESS!=rc&_rec' is 
redundant or there is possible null pointer dereference: curr_rec.
[src/amf/amfnd/clc.cc:1404] -> [src/amf/amfnd/clc.cc:1408]: (warning, 
inconclusive) Either the condition 'NCSCC_RC_SUCCESS!=rc&_rec' is 
redundant or there is possible null pointer dereference: curr_rec.
[src/amf/amfnd/clc.cc:610] -> [src/amf/amfnd/clc.cc:616]: (style) Variable 
'clc_evt' is reassigned a value before the old one has been used.
[src/amf/amfnd/clc.cc:1708] -> [src/amf/amfnd/clc.cc:1712]: (style) Variable 
'rc' is reassigned a value before the old one has been used.
[src/amf/amfnd/clc.cc:1749] -> [src/amf/amfnd/clc.cc:1753]: (style) Variable 
'rc' is reassigned a value before the old one has been used.
[src/amf/amfnd/clc.cc:1951] -> [src/amf/amfnd/clc.cc:1955]: (style) Variable 
'rc' is reassigned a value before the old one has been used.
[src/amf/amfnd/clc.cc:2370] -> [src/amf/amfnd/clc.cc:2376]: (style) Variable 
'csi' is reassigned a value before the old one has been used.
[src/amf/amfnd/clc.cc:3052] -> [src/amf/amfnd/clc.cc:3053]: (style) Variable 
'tmp' is reassigned a value before the old one has been used.
[src/amf/amfnd/clc.cc:3172] -> [src/amf/amfnd/clc.cc:3181]: (style) Variable 
'rc' is reassigned a value before the old one has been used.
[src/amf/amfnd/clc.cc:1356]: (style) The scope of the variable 'curr_rec' can 
be reduced.
[src/amf/amfnd/clc.cc:1384]: (style) The scope of the variable 'curr_rec' can 
be reduced.
[src/amf/amfnd/clc.cc:3042]: (style) The scope of the variable 'i' can be 
reduced.
[src/amf/amfnd/comp.cc:2557] -> [src/amf/amfnd/comp.cc:2561]: (warning) Either 
the condition 'if(csi&_AVND_COMP_IS_ALL_CSI(comp))' is redundant or there is 
possible null pointer dereference: csi.
[src/amf/amfnd/comp.cc:2237] -> [src/amf/amfnd/comp.cc:2250]: (style) Variable 
'rc' is reassigned a value before the old one has been used.
[src/amf/amfnd/comp.cc:2962] -> [src/amf/amfnd/comp.cc:2972]: (style) Variable 
'rc' is reassigned a value before the old one has been used.
[src/amf/amfnd/compdb.cc:485]: (warning) Comparison of a boolean expression 
with an integer.
[src/amf/amfnd/compdb.cc:486]: (warning) Comparison of a boolean expression 
with an integer.
[src/amf/amfnd/compdb.cc:485]: (warning) Comparison of a boolean value using 
relational operator (<, >, <= or >=).
[src/amf/amfnd/compdb.cc:732] -> [src/amf/amfnd/compdb.cc:734]: (warning) 
Either the