osaf/libs/common/ais/aisa_api.c | 2 +
osaf/libs/core/common/daemon.c | 60 ++-
osaf/libs/core/common/include/osaf_secutil.h | 14 +-
osaf/libs/core/common/ncs_main_pub.c | 19 +-
osaf/libs/core/common/nid_start_util.c | 4 +-
osaf/libs/core/common/osaf_extended_name.c | 1 +
osaf/libs/core/common/osaf_poll.c | 13 +-
osaf/libs/core/common/osaf_secutil.c | 223 +++++++-------
osaf/libs/core/common/osaf_timerfd.c | 2 +
osaf/libs/core/cplusplus/base/tests/time_compare_test.cc | 12 +
osaf/libs/core/include/ncspatricia.h | 3 -
osaf/libs/core/leap/hj_edp.c | 17 +-
osaf/libs/core/leap/hj_edu.c | 52 +-
osaf/libs/core/leap/hj_enc.c | 2 +-
osaf/libs/core/leap/hj_hdl.c | 29 +-
osaf/libs/core/leap/hj_tmr.c | 9 +-
osaf/libs/core/leap/hj_ubaid.c | 3 +-
osaf/libs/core/leap/os_defs.c | 19 +-
osaf/libs/core/leap/sysf_exc_scr.c | 27 +-
osaf/libs/core/leap/sysf_ipc.c | 4 +-
osaf/libs/core/leap/sysf_mem.c | 9 +-
osaf/libs/core/leap/sysf_tmr.c | 7 +-
osaf/libs/core/leap/sysf_tsk.c | 7 +
osaf/libs/core/leap/tests/sysf_ipc_test.cc | 18 +-
osaf/libs/core/leap/tests/sysf_tmr_test.cc | 4 +-
25 files changed, 263 insertions(+), 297 deletions(-)
The following warnings, reported by cppcheck version 1.74, have been fixed:
[osaf/libs/core/common/daemon.c:212]: (style) The scope of the variable
'plibc_prctl' can be reduced.
[osaf/libs/core/common/daemon.c:214]: (style) The scope of the variable 'pid'
can be reduced.
[osaf/libs/core/common/daemon.c:214]: (style) The scope of the variable 'sid'
can be reduced.
[osaf/libs/core/common/daemon.c:505]: (style) The scope of the variable
'bt_filename_size' can be reduced.
[osaf/libs/core/common/daemon.c:507]: (style) The scope of the variable
'time_string' can be reduced.
[osaf/libs/core/common/daemon.c:510]: (style) The scope of the variable 'i' can
be reduced.
[osaf/libs/core/common/daemon.c:340]: (portability) Non reentrant function
'getpwnam' called. For threadsafe applications it is recommended to use the
reentrant replacement function 'getpwnam_r'.
[osaf/libs/core/common/daemon.c:533]: (portability) Non reentrant function
'localtime' called. For threadsafe applications it is recommended to use the
reentrant replacement function 'localtime_r'.
[osaf/libs/core/common/daemon.c:256]: (error) Uninitialized variable: param
[osaf/libs/core/common/daemon.c:528]: (error) Uninitialized variable:
time_string
[osaf/libs/core/common/daemon.c:539]: (error) Uninitialized variable:
time_string
[osaf/libs/core/common/ncs_main_pub.c:178] ->
[osaf/libs/core/common/ncs_main_pub.c:180]: (style) Variable 'rc' is reassigned
a value before the old one has been used.
[osaf/libs/core/common/ncs_main_pub.c:315] ->
[osaf/libs/core/common/ncs_main_pub.c:317]: (style) Variable 'rc' is reassigned
a value before the old one has been used.
[osaf/libs/core/common/ncs_main_pub.c:714]: (style) The scope of the variable
'p_field' can be reduced.
[osaf/libs/core/common/ncs_main_pub.c:794]: (style) The scope of the variable
'tmp' can be reduced.
[osaf/libs/core/common/ncs_main_pub.c:129]: (style) struct member
'ncs_main_pub_cb::lock_create' is never used.
[osaf/libs/core/common/ncs_main_pub.c:693]: (style) Variable 'res' is assigned
a value that is never used.
[osaf/libs/core/common/nid_start_util.c:54]: (warning) fscanf() without field
width limits can crash with huge input data.
[osaf/libs/core/common/osaf_extended_name.c:183]: (error) Memory is allocated
but not initialized: pointer
[osaf/libs/core/common/osaf_poll.c:117]: (error) Uninitialized variable:
elapsed_time
[osaf/libs/core/common/osaf_poll.c:118]: (error) Uninitialized variable:
elapsed_time
[osaf/libs/core/common/osaf_poll.c:120]: (error) Uninitialized variable:
elapsed_time
[osaf/libs/core/common/osaf_poll.c:134]: (error) Uninitialized variable: set
[osaf/libs/core/common/osaf_poll.c:135]: (error) Uninitialized variable: set
[osaf/libs/core/common/osaf_secutil.c:243]: (portability) Non reentrant
function 'getpwuid' called. For threadsafe applications it is recommended to
use the reentrant replacement function 'getpwuid_r'.
[osaf/libs/core/common/osaf_secutil.c:353]: (portability) Non reentrant
function 'getpwuid' called. For threadsafe applications it is recommended to
use the reentrant replacement function 'getpwuid_r'.
[osaf/libs/core/common/osaf_secutil.c:370]: (portability) Non reentrant
function 'getgrent' called. For threadsafe applications it is recommended to
use the reentrant replacement function 'getgrent_r'.
[osaf/libs/core/common/osaf_secutil.c:379]: (portability) Non reentrant
function 'getgrent' called. For threadsafe applications it is recommended to
use the reentrant replacement function 'getgrent_r'.
[osaf/libs/core/common/osaf_secutil.c:399]: (portability) Non reentrant
function 'getgrent' called. For threadsafe applications it is recommended to
use the reentrant replacement function 'getgrent_r'.
[osaf/libs/core/common/osaf_secutil.c:82]: (error) Uninitialized variable: fds
[osaf/libs/core/common/osaf_secutil.c:83]: (error) Uninitialized variable: fds
[osaf/libs/core/common/osaf_secutil.c:136]: (error) Uninitialized variable:
unaddr
[osaf/libs/core/common/osaf_secutil.c:170]: (error) Uninitialized variable: fds
[osaf/libs/core/common/osaf_secutil.c:171]: (error) Uninitialized variable: fds
[osaf/libs/core/common/osaf_secutil.c:203]: (error) Memory is allocated but not
initialized: fd
[osaf/libs/core/common/osaf_secutil.c:279]: (error) Uninitialized variable:
remote
[osaf/libs/core/common/osaf_secutil.c:295]: (error) Uninitialized variable: fds
[osaf/libs/core/common/osaf_secutil.c:296]: (error) Uninitialized variable: fds
[osaf/libs/core/common/osaf_timerfd.c:184]: (error) Uninitialized variable:
event
[osaf/libs/core/common/osaf_timerfd.c:185]: (error) Uninitialized variable:
event
[osaf/libs/core/common/osaf_timerfd.c:186]: (error) Uninitialized variable:
event
[osaf/libs/core/common/osaf_timerfd.c:187]: (error) Uninitialized variable:
event
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:25] ->
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:25]: (style) Same
expression on both sides of '<'.
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:26] ->
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:26]: (style) Same
expression on both sides of '<='.
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:29] ->
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:29]: (style) Same
expression on both sides of '>='.
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:30] ->
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:30]: (style) Same
expression on both sides of '>'.
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:70] ->
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:70]: (style) Same
expression on both sides of '<'.
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:71] ->
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:71]: (style) Same
expression on both sides of '<='.
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:74] ->
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:74]: (style) Same
expression on both sides of '>='.
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:75] ->
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:75]: (style) Same
expression on both sides of '>'.
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:97] ->
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:97]: (style) Same
expression on both sides of '<'.
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:98] ->
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:98]: (style) Same
expression on both sides of '<='.
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:101] ->
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:101]: (style) Same
expression on both sides of '>='.
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:102] ->
[osaf/libs/core/cplusplus/base/tests/time_compare_test.cc:102]: (style) Same
expression on both sides of '>'.
[osaf/libs/core/leap/hj_edp.c:169]: (style) The scope of the variable 'len' can
be reduced.
[osaf/libs/core/leap/hj_edp.c:352]: (style) The scope of the variable 'len' can
be reduced.
[osaf/libs/core/leap/hj_edp.c:352]: (style) The scope of the variable
'byte_cnt' can be reduced.
[osaf/libs/core/leap/hj_edp.c:778]: (style) The scope of the variable
'byte_cnt' can be reduced.
[osaf/libs/core/leap/hj_edp.c:1661]: (warning) Division by result of sizeof().
malloc() expects a size in bytes, did you intend to multiply instead?
[osaf/libs/core/leap/hj_edp.c:1813]: (warning) Division by result of sizeof().
malloc() expects a size in bytes, did you intend to multiply instead?
[osaf/libs/core/leap/hj_edu.c:132]: (style) The scope of the variable
'arguments' can be reduced.
[osaf/libs/core/leap/hj_edu.c:284]: (style) The scope of the variable
'arguments' can be reduced.
[osaf/libs/core/leap/hj_edu.c:413]: (style) The scope of the variable
'dtype_attrb' can be reduced.
[osaf/libs/core/leap/hj_edu.c:415]: (style) The scope of the variable 'cnt' can
be reduced.
[osaf/libs/core/leap/hj_edu.c:2478]: (style) The scope of the variable 'lclfnd'
can be reduced.
[osaf/libs/core/leap/hj_edu.c:2528]: (style) The scope of the variable
'already_added' can be reduced.
[osaf/libs/core/leap/hj_edu.c:3244]: (style) The scope of the variable
'new_node' can be reduced.
[osaf/libs/core/leap/hj_edu.c:3321]: (style) The scope of the variable 'key'
can be reduced.
[osaf/libs/core/leap/hj_edu.c:3322]: (style) The scope of the variable 'pnode'
can be reduced.
[osaf/libs/core/leap/hj_edu.c:3447]: (style) The scope of the variable 'val'
can be reduced.
[osaf/libs/core/leap/hj_edu.c:3499]: (style) The scope of the variable 'val'
can be reduced.
[osaf/libs/core/leap/hj_edu.c:3529]: (style) The scope of the variable 'i' can
be reduced.
[osaf/libs/core/leap/hj_edu.c:3626]: (style) The scope of the variable 'val'
can be reduced.
[osaf/libs/core/leap/hj_edu.c:3679]: (style) The scope of the variable 'val'
can be reduced.
[osaf/libs/core/leap/hj_edu.c:498]: (style) Variable 'admin_op' is assigned a
value that is never used.
[osaf/libs/core/leap/hj_edu.c:3328]: (style) Variable 'lcl_key' is assigned a
value that is never used.
[osaf/libs/core/leap/hj_edu.c:445]: (error) Uninitialized variable: admin_op
[osaf/libs/core/leap/hj_edu.c:446]: (error) Uninitialized variable: admin_op
[osaf/libs/core/leap/hj_edu.c:3296]: (error) Uninitialized variable: list_params
[osaf/libs/core/leap/hj_enc.c:58]: (style) The scope of the variable 'p' can be
reduced.
[osaf/libs/core/leap/hj_hdl.c:231]: (style) The scope of the variable 'unit'
can be reduced.
[osaf/libs/core/leap/hj_hdl.c:271]: (style) The scope of the variable 'cell'
can be reduced.
[osaf/libs/core/leap/hj_hdl.c:311]: (style) The scope of the variable 'cell'
can be reduced.
[osaf/libs/core/leap/hj_hdl.c:547]: (style) The scope of the variable 'cell'
can be reduced.
[osaf/libs/core/leap/hj_hdl.c:613]: (style) The scope of the variable 'cell'
can be reduced.
[osaf/libs/core/leap/hj_hdl.c:617]: (style) The scope of the variable 'i' can
be reduced.
[osaf/libs/core/leap/hj_hdl.c:193]: (error) Uninitialized variable: ha
[osaf/libs/core/leap/hj_hdl.c:194]: (error) Uninitialized variable: ha
[osaf/libs/core/leap/hj_hdl.c:195]: (error) Uninitialized variable: ha
[osaf/libs/core/leap/hj_hdl.c:196]: (error) Uninitialized variable: ha
[osaf/libs/core/leap/hj_hdl.c:578]: (error) Uninitialized variable: hdl
[osaf/libs/core/leap/hj_hdl.c:579]: (error) Uninitialized variable: hdl
[osaf/libs/core/leap/hj_hdl.c:580]: (error) Uninitialized variable: hdl
[osaf/libs/core/leap/hj_tmr.c:389]: (style) The scope of the variable
'tmr_info' can be reduced.
[osaf/libs/core/leap/hj_tmr.c:425]: (style) The scope of the variable
'pres_tmr_info' can be reduced.
[osaf/libs/core/leap/hj_tmr.c:471]: (style) The scope of the variable
'prev_tmr_info' can be reduced.
[osaf/libs/core/leap/hj_ubaid.c:708]: (style) The scope of the variable 'p' can
be reduced.
[osaf/libs/core/leap/os_defs.c:505]: (style) The scope of the variable
'tmp_hdl' can be reduced.
[osaf/libs/core/leap/os_defs.c:645]: (style) The scope of the variable 'file'
can be reduced.
[osaf/libs/core/leap/os_defs.c:773]: (style) The scope of the variable
'prot_flag' can be reduced.
[osaf/libs/core/leap/os_defs.c:593]: (error) Uninitialized variable: os_req
[osaf/libs/core/leap/os_defs.c:595]: (error) Uninitialized variable: os_req
[osaf/libs/core/leap/os_defs.c:597]: (error) Uninitialized variable: os_req
[osaf/libs/core/leap/os_defs.c:598]: (error) Uninitialized variable: os_req
[osaf/libs/core/leap/os_defs.c:599]: (error) Uninitialized variable: os_req
[osaf/libs/core/leap/os_defs.c:600]: (error) Uninitialized variable: os_req
[osaf/libs/core/leap/os_defs.c:614]: (error) Uninitialized variable: os_req
[osaf/libs/core/leap/os_defs.c:616]: (error) Uninitialized variable: os_req
[osaf/libs/core/leap/os_defs.c:618]: (error) Uninitialized variable: os_req
[osaf/libs/core/leap/os_defs.c:619]: (error) Uninitialized variable: os_req
[osaf/libs/core/leap/os_defs.c:620]: (error) Uninitialized variable: os_req
[osaf/libs/core/leap/os_defs.c:621]: (error) Uninitialized variable: os_req
[osaf/libs/core/leap/os_defs.c:654]: (error) Uninitialized variable: os_req
[osaf/libs/core/leap/os_defs.c:661]: (error) Uninitialized variable: os_req
[osaf/libs/core/leap/os_defs.c:667]: (error) Uninitialized variable: os_req
[osaf/libs/core/leap/os_defs.c:670]: (error) Uninitialized variable: os_req
[osaf/libs/core/leap/os_defs.c:694]: (error) Uninitialized variable: os_req
[osaf/libs/core/leap/os_defs.c:695]: (error) Uninitialized variable: os_req
[osaf/libs/core/leap/os_defs.c:696]: (error) Uninitialized variable: os_req
[osaf/libs/core/leap/os_defs.c:706]: (error) Uninitialized variable: os_req
[osaf/libs/core/leap/os_defs.c:707]: (error) Uninitialized variable: os_req
[osaf/libs/core/leap/sysf_exc_scr.c:460]: (style) The scope of the variable
'exec_pid' can be reduced.
[osaf/libs/core/leap/sysf_exc_scr.c:109]: (error) Uninitialized variable: info
[osaf/libs/core/leap/sysf_exc_scr.c:110]: (error) Uninitialized variable: info
[osaf/libs/core/leap/sysf_exc_scr.c:111]: (error) Uninitialized variable: info
[osaf/libs/core/leap/sysf_exc_scr.c:146]: (error) Uninitialized variable: info
[osaf/libs/core/leap/sysf_exc_scr.c:147]: (error) Uninitialized variable: info
[osaf/libs/core/leap/sysf_exc_scr.c:148]: (error) Uninitialized variable: info
[osaf/libs/core/leap/sysf_exc_scr.c:404]: (error) Uninitialized variable:
pt_params
[osaf/libs/core/leap/sysf_ipc.c:454]: (style) The scope of the variable
'inds_rmvd' can be reduced.
[osaf/libs/core/leap/sysf_mem.c:854]: (style) The scope of the variable 'pub'
can be reduced.
[osaf/libs/core/leap/sysf_mem.c:856]: (style) The scope of the variable
'buflen' can be reduced.
[osaf/libs/core/leap/sysf_mem.c:944]: (style) The scope of the variable
'buflen' can be reduced.
[osaf/libs/core/leap/sysf_mem.c:1162]: (style) The scope of the variable 'i'
can be reduced.
[osaf/libs/core/leap/sysf_mem.c:1170]: (style) The scope of the variable 'dest'
can be reduced.
[osaf/libs/core/leap/sysf_mem.c:1478]: (style) The scope of the variable
'bufsize' can be reduced.
[osaf/libs/core/leap/sysf_mem.c:1735]: (style) The scope of the variable 'len'
can be reduced.
[osaf/libs/core/leap/sysf_mem.c:1736]: (style) The scope of the variable 'dst'
can be reduced.
[osaf/libs/core/leap/sysf_mem.c:1917]: (style) The scope of the variable 'file'
can be reduced.
[osaf/libs/core/leap/sysf_mem.c:747]: (error) Uninitialized variable: l_util
[osaf/libs/core/leap/sysf_tmr.c:390]: (style) The scope of the variable 'rc'
can be reduced.
[osaf/libs/core/leap/sysf_tmr.c:545]: (style) The scope of the variable
'free_tmr' can be reduced.
[osaf/libs/core/leap/sysf_tmr.c:166]: (style) struct member
'sysf_tmr_cb::stats' is never used.
[osaf/libs/core/leap/sysf_tsk.c:53]: (error) Uninitialized variable: task
[osaf/libs/core/leap/sysf_tsk.c:54]: (error) Uninitialized variable: task
[osaf/libs/core/leap/sysf_tsk.c:55]: (error) Uninitialized variable: task
[osaf/libs/core/leap/sysf_tsk.c:56]: (error) Uninitialized variable: task
[osaf/libs/core/leap/sysf_tsk.c:57]: (error) Uninitialized variable: task
[osaf/libs/core/leap/sysf_tsk.c:58]: (error) Uninitialized variable: task
[osaf/libs/core/leap/sysf_tsk.c:75]: (error) Uninitialized variable: task
[osaf/libs/core/leap/sysf_tsk.c:87]: (error) Uninitialized variable: task
[osaf/libs/core/leap/sysf_tsk.c:99]: (error) Uninitialized variable: task
[osaf/libs/core/leap/sysf_tsk.c:111]: (error) Uninitialized variable: task
[osaf/libs/core/leap/sysf_tsk.c:123]: (error) Uninitialized variable: task
[osaf/libs/core/leap/sysf_tsk.c:132]: (error) Uninitialized variable: task
[osaf/libs/core/leap/tests/sysf_ipc_test.cc:74] ->
[osaf/libs/core/leap/tests/sysf_ipc_test.cc:78]: (style) Variable 'rc' is
reassigned a value before the old one has been used.
[osaf/libs/core/leap/tests/sysf_ipc_test.cc:41]: (style) The scope of the
variable 'temp' can be reduced.
[osaf/libs/core/leap/tests/sysf_ipc_test.cc:123]: (style) The scope of the
variable 'msg' can be reduced.
[osaf/libs/core/leap/tests/sysf_ipc_test.cc:124]: (style) The scope of the
variable 'prio' can be reduced.
[osaf/libs/core/leap/tests/sysf_ipc_test.cc:126]: (style) The scope of the
variable 'rc' can be reduced.
[osaf/libs/core/leap/tests/sysf_tmr_test.cc:18]: (warning) Member variable
'SysfTmrTest::timers_' is not initialized in the constructor.
diff --git a/osaf/libs/common/ais/aisa_api.c b/osaf/libs/common/ais/aisa_api.c
--- a/osaf/libs/common/ais/aisa_api.c
+++ b/osaf/libs/common/ais/aisa_api.c
@@ -103,11 +103,13 @@ void saAisNameLend(SaConstStringT value,
SaConstStringT saAisNameBorrow(const SaNameT* name)
__attribute__ ((weak, alias ("ais_name_borrow")));
+// cppcheck-suppress unusedFunction
void ais_name_lend(SaConstStringT value, SaNameT* name)
{
osaf_extended_name_lend(value, name);
}
+// cppcheck-suppress unusedFunction
SaConstStringT ais_name_borrow(const SaNameT* name)
{
SaConstStringT value = osaf_extended_name_borrow(name);
diff --git a/osaf/libs/core/common/daemon.c b/osaf/libs/core/common/daemon.c
--- a/osaf/libs/core/common/daemon.c
+++ b/osaf/libs/core/common/daemon.c
@@ -208,11 +208,7 @@ static void __parse_options(int argc, ch
void daemonize(int argc, char *argv[])
{
-#ifndef RUNASROOT
- static int (*plibc_prctl) (int option, ...) = NULL;
-#endif
- pid_t pid, sid;
- struct sched_param param;
+ struct sched_param param = { 0 };
char *thread_prio;
char *thread_policy;
int policy = SCHED_OTHER; /*root defaults */
@@ -283,7 +279,7 @@ void daemonize(int argc, char *argv[])
if (getppid() == 1) return;
/* Fork off the parent process */
- pid = fork();
+ pid_t pid = fork();
if (pid < 0) {
syslog(LOG_ERR, "fork daemon failed, pid=%d (%s)", pid,
strerror(errno));
exit(EXIT_FAILURE);
@@ -293,7 +289,7 @@ void daemonize(int argc, char *argv[])
if (pid > 0) exit(EXIT_SUCCESS);
/* Create a new SID for the child process */
- sid = setsid();
+ pid_t sid = setsid();
if (sid < 0) {
syslog(LOG_ERR, "create new session failed, sid=%d
(%s)", sid, strerror(errno));
exit(EXIT_FAILURE);
@@ -337,13 +333,18 @@ void daemonize(int argc, char *argv[])
#ifndef RUNASROOT
/* Drop privileges to user if there is one, and we were run as root */
if (getuid() == 0 || geteuid() == 0) {
- struct passwd *pw = getpwnam(__runas_username);
- if (pw) {
+ long bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
+ char* buffer = (char*) malloc(bufsize >= 0 ? bufsize : 16384);
+ struct passwd pwd;
+ struct passwd* pw;
+ if (buffer != NULL && getpwnam_r(__runas_username, &pwd,
buffer, bufsize, &pw) == 0 && pw != NULL) {
/* supplementary groups */
- int ngroups = 0;
- if (osaf_get_group_list(pw->pw_uid, pw->pw_gid, NULL,
&ngroups) == 0) {
- gid_t * group_ids = (gid_t*) malloc(ngroups *
sizeof(gid_t));
- if (osaf_get_group_list(pw->pw_uid, pw->pw_gid,
group_ids, &ngroups) > 0) {
+ int ngroups = 1;
+ gid_t gid;
+ osaf_getgrouplist(__runas_username, pw->pw_gid, &gid,
&ngroups);
+ gid_t* group_ids = (gid_t*) malloc(ngroups *
sizeof(gid_t));
+ if (group_ids != NULL) {
+ if (osaf_getgrouplist(__runas_username,
pw->pw_gid, group_ids, &ngroups) != -1) {
// TODO: setgroups() is non POSIX, fix
it later
if (setgroups(ngroups, group_ids)) {
syslog(LOG_INFO, "setgroups
failed, uid=%d (%s). Continuing without supplementary groups.", pw->pw_uid,
strerror(errno));
@@ -357,14 +358,16 @@ void daemonize(int argc, char *argv[])
}
if ((pw->pw_gid > 0) && (setgid(pw->pw_gid) < 0)) {
syslog(LOG_ERR, "setgid failed, gid=%d (%s)",
pw->pw_gid, strerror(errno));
+ free(buffer);
exit(EXIT_FAILURE);
}
if ((pw->pw_uid > 0) && (setuid(pw->pw_uid) < 0)) {
syslog(LOG_ERR, "setuid failed, uid=%d (%s)",
pw->pw_uid, strerror(errno));
+ free(buffer);
exit(EXIT_FAILURE);
}
// Enable generating core files
- plibc_prctl = dlsym(RTLD_DEFAULT, "prctl");
+ int (*plibc_prctl) (int option, ...) =
dlsym(RTLD_DEFAULT, "prctl");
if (plibc_prctl) {
if (plibc_prctl(PR_SET_DUMPABLE, 1) < 0) {
syslog(LOG_ERR, "prctl failed: %s",
strerror(errno));
@@ -372,8 +375,10 @@ void daemonize(int argc, char *argv[])
}
} else {
syslog(LOG_ERR, "invalid user name %s",
__runas_username);
+ free(buffer);
exit(EXIT_FAILURE);
}
+ free(buffer);
}
#endif
@@ -502,12 +507,6 @@ done:
*/
static void install_fatal_signal_handlers(void)
{
- size_t bt_filename_size = 0;
- time_t current_time;
- char time_string[20];
-
- struct sigaction action;
- int i = 0;
const int HANDLED_SIGNALS_MAX = 7;
static const int handled_signals[] = {
SIGHUP,
@@ -523,31 +522,38 @@ static void install_fatal_signal_handler
if (init_backtrace_fptrs() < 0) {
syslog(LOG_WARNING, "backtrace symbols not found, no fatal
signal handlers will be installed");
} else {
-
- // prepare a filename for backtrace
- time_string[0] = '\0';
+ char time_string[20] = { 0 };
+ time_t current_time;
if (time(¤t_time) < 0) {
syslog(LOG_WARNING, "time failed: %s", strerror(errno));
} else {
- if (strftime(time_string, sizeof(time_string),
"%Y%m%d_%T", localtime(¤t_time)) == 0) {
- syslog(LOG_WARNING, "strftime failed");
+ struct tm result;
+ struct tm* local_time = localtime_r(¤t_time,
&result);
+ if (local_time != NULL) {
+ if (strftime(time_string, sizeof(time_string),
"%Y%m%d_%T", local_time) == 0) {
+ syslog(LOG_WARNING, "strftime failed");
+ time_string[0] = '\0';
+ }
+ } else {
+ syslog(LOG_WARNING, "localtime_r failed");
}
}
// 16 = "/bt__" (5) + sizeof pid_t (10) + \0 (1)
- bt_filename_size = strlen(PKGLOGDIR) + strlen(time_string) + 16;
+ size_t bt_filename_size = strlen(PKGLOGDIR) +
strlen(time_string) + 16;
bt_filename = (char *) malloc(bt_filename_size);
snprintf(bt_filename, bt_filename_size, PKGLOGDIR "/bt_%s_%d",
time_string, getpid());
+ struct sigaction action;
memset(&action, 0, sizeof(action));
action.sa_sigaction = fatal_signal_handler;
sigfillset(&action.sa_mask);
action.sa_flags = SA_RESETHAND | SA_SIGINFO;
- for (i = 0; i < HANDLED_SIGNALS_MAX; ++i) {
+ for (int i = 0; i < HANDLED_SIGNALS_MAX; ++i) {
if (sigaction(handled_signals[i], &action, NULL) < 0) {
syslog(LOG_WARNING, "sigaction %d failed: %s",
handled_signals[i], strerror(errno));
}
diff --git a/osaf/libs/core/common/include/osaf_secutil.h
b/osaf/libs/core/common/include/osaf_secutil.h
--- a/osaf/libs/core/common/include/osaf_secutil.h
+++ b/osaf/libs/core/common/include/osaf_secutil.h
@@ -92,18 +92,10 @@ bool osaf_user_is_member_of_group(uid_t
* Get list of groups that a user belong to
* There already is a function in LSB for this purpose (getgrouplist) but it
is not standard.
*
- * @param uid: user to search
- * @oaram gid: default group will be put in the list (pw_gid of user's passwd
struct)
- * @param groups: pointer to the array that the result will be returned
- * When groups is NULL, this function will return 0 on succeeded
and
- * ngroups can be used to allocate space for groups.
- * @param ngroups: when return successfully it always contains the number of
groups.
- *
- * @return -1 on failure
- * 0 on succeeded to find number of groups
- * Otherwise, the number of found groups.
+ * This function provides the same interface as getgrouplist(3) in glibc.
Refer to the man
+ * page for the interface description.
*/
-int osaf_get_group_list(const uid_t uid, const gid_t gid, gid_t *groups, int
*ngroups);
+int osaf_getgrouplist(const char* user, gid_t group, gid_t* groups, int*
ngroups);
#ifdef __cplusplus
}
diff --git a/osaf/libs/core/common/ncs_main_pub.c
b/osaf/libs/core/common/ncs_main_pub.c
--- a/osaf/libs/core/common/ncs_main_pub.c
+++ b/osaf/libs/core/common/ncs_main_pub.c
@@ -126,7 +126,6 @@ typedef struct ncs_main_pub_cb {
void *lib_hdl;
NCS_LOCK lock;
- uint32_t lock_create;
bool core_started;
uint32_t my_nodeid;
uint32_t my_procid;
@@ -175,9 +174,7 @@ static pthread_mutex_t s_leap_core_mutex
\***************************************************************************/
unsigned int ncs_agents_startup(void)
{
- uint32_t rc = NCSCC_RC_SUCCESS;
-
- rc = ncs_core_agents_startup();
+ uint32_t rc = ncs_core_agents_startup();
if (rc != NCSCC_RC_SUCCESS)
return rc;
@@ -312,9 +309,7 @@ unsigned int ncs_mds_startup(void)
\***************************************************************************/
uint32_t ncs_non_core_agents_startup(void)
{
- uint32_t rc = NCSCC_RC_SUCCESS;
-
- rc = ncs_mbca_startup();
+ uint32_t rc = ncs_mbca_startup();
return rc;
}
@@ -686,11 +681,10 @@ static uint32_t ncs_set_config_root(void
uint32_t ncs_util_get_sys_params(NCS_SYS_PARAMS *sys_params)
{
char *tmp_ptr;
- uint32_t res = NCSCC_RC_SUCCESS;
memset(sys_params, 0, sizeof(NCS_SYS_PARAMS));
- if ((res = ncs_set_config_root()) != NCSCC_RC_SUCCESS) {
+ if (ncs_set_config_root() != NCSCC_RC_SUCCESS) {
TRACE_4("Unable to set config root \n");
return NCSCC_RC_FAILURE;
}
@@ -711,7 +705,6 @@ uint32_t ncs_util_get_sys_params(NCS_SYS
void ncs_get_sys_params_arg(NCS_SYS_PARAMS *sys_params)
{
- char *p_field;
uint32_t tmp_ctr;
uint32_t orig_argc;
NCS_SYS_PARAMS params;
@@ -728,7 +721,7 @@ void ncs_get_sys_params_arg(NCS_SYS_PARA
/* Check argv[argc-1] through argv[1] */
for (; argc > 1; argc--) {
- p_field = strstr(&argv[argc - 1], "NODE_ID=");
+ char* p_field = strstr(&argv[argc - 1], "NODE_ID=");
if (p_field != NULL) {
if (sscanf(p_field + strlen("NODE_ID="), "%d",
¶ms.node_id) == 1)
sys_params->node_id = params.node_id;
@@ -791,11 +784,9 @@ uint32_t ncs_update_sys_param_args(void)
\***************************************************************************/
char *ncs_util_search_argv_list(int argc, char *argv[], char *arg_prefix)
{
- char *tmp;
-
/* Check argv[argc-1] through argv[1] */
for (; argc > 1; argc--) {
- tmp = strstr(argv[argc - 1], arg_prefix);
+ char* tmp = strstr(argv[argc - 1], arg_prefix);
if (tmp != NULL)
return tmp;
}
diff --git a/osaf/libs/core/common/nid_start_util.c
b/osaf/libs/core/common/nid_start_util.c
--- a/osaf/libs/core/common/nid_start_util.c
+++ b/osaf/libs/core/common/nid_start_util.c
@@ -37,7 +37,7 @@
unsigned int amf_comp_name_get_set_from_file(const char *env_name, SaNameT *dn)
{
unsigned int rc = NCSCC_RC_FAILURE;
- char comp_name[SA_MAX_NAME_LENGTH] = { 0 };
+ char comp_name[257] = { 0 };
FILE *fp;
char *comp_name_file;
@@ -51,7 +51,7 @@ unsigned int amf_comp_name_get_set_from_
goto done;
}
- if (fscanf(fp, "%s", comp_name) != 1) {
+ if (fscanf(fp, "%256s", comp_name) != 1) {
(void)fclose(fp);
LOG_ER("Unable to retrieve component name from file '%s'",
comp_name_file);
goto done;
diff --git a/osaf/libs/core/common/osaf_extended_name.c
b/osaf/libs/core/common/osaf_extended_name.c
--- a/osaf/libs/core/common/osaf_extended_name.c
+++ b/osaf/libs/core/common/osaf_extended_name.c
@@ -180,6 +180,7 @@ void osaf_extended_name_alloc(SaConstStr
pointer = name->_opaque + 1;
} else {
pointer = malloc(length + 1);
+ // cppcheck-suppress uninitdata
set_ptr(pointer, name);
}
memcpy(pointer, value, length + 1);
diff --git a/osaf/libs/core/common/osaf_poll.c
b/osaf/libs/core/common/osaf_poll.c
--- a/osaf/libs/core/common/osaf_poll.c
+++ b/osaf/libs/core/common/osaf_poll.c
@@ -82,7 +82,7 @@ unsigned osaf_ppoll(struct pollfd* io_fd
for (;;) {
struct timespec current_time;
- struct timespec elapsed_time;
+ struct timespec elapsed_time = { .tv_sec = 0, .tv_nsec = 0 };
int time_left;
/* We don't want to time-out too early, so round up to next even
@@ -109,13 +109,6 @@ unsigned osaf_ppoll(struct pollfd* io_fd
if (osaf_timespec_compare(¤t_time, &start_time) >= 0) {
osaf_timespec_subtract(¤t_time, &start_time,
&elapsed_time);
- } else {
- /* Handle the unlikely case that the elapsed time is
- * negative. Shouldn't happen with a monotonic clock,
- * but just to be on the safe side.
- */
- elapsed_time.tv_sec = 0;
- elapsed_time.tv_nsec = 0;
}
if (osaf_timespec_compare(&elapsed_time, i_timeout_ts) >= 0) {
result = 0;
@@ -129,10 +122,8 @@ unsigned osaf_ppoll(struct pollfd* io_fd
int osaf_poll_one_fd(int i_fd, int i_timeout)
{
- struct pollfd set;
+ struct pollfd set = { .fd = i_fd, .events = POLLIN, .revents = 0 };
unsigned result;
- set.fd = i_fd;
- set.events = POLLIN;
result = osaf_poll(&set, 1, i_timeout);
if (result == 1) {
if ((set.revents & (POLLNVAL | POLLERR)) != 0) {
diff --git a/osaf/libs/core/common/osaf_secutil.c
b/osaf/libs/core/common/osaf_secutil.c
--- a/osaf/libs/core/common/osaf_secutil.c
+++ b/osaf/libs/core/common/osaf_secutil.c
@@ -48,6 +48,9 @@
#include "logtrace.h"
#include "include/osaf_secutil.h"
+static struct group* osaf_getgrent_r(struct group *gbuf, char** buf,
+ size_t* buflen);
+
// singleton (one per process) callback
static client_auth_data_callback_t client_auth_data_callback;
@@ -78,9 +81,7 @@ static void handle_new_connection(int se
}
// wait a while for data to get available on socket
- struct pollfd fds;
- fds.fd = client_fd;
- fds.events = POLLIN;
+ struct pollfd fds = { .fd = client_fd, .events = POLLIN, .revents = 0 };
int timeout = 10000; // TODO allow configuration?
int res = osaf_poll(&fds, 1, timeout);
@@ -111,7 +112,7 @@ static int server_sock_create(const char
{
int server_sockfd;
socklen_t addrlen;
- struct sockaddr_un unaddr;
+ struct sockaddr_un unaddr = { 0 };
if ((server_sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
LOG_ER("%s: socket failed - %s", __FUNCTION__, strerror(errno));
@@ -161,19 +162,16 @@ static int server_sock_create(const char
static void *auth_server_main(void *_fd)
{
int fd = *((int*) _fd);
- struct pollfd fds[1];
+ struct pollfd fds = { .fd = fd, .events = POLLIN, .revents = 0 };
TRACE_ENTER();
free(_fd);
- fds[0].fd = fd;
- fds[0].events = POLLIN;
+ for (;;) {
+ osaf_poll(&fds, 1, -1);
- while (1) {
- (void) osaf_poll(fds, 1, -1);
-
- if (fds[0].revents & POLLIN) {
+ if (fds.revents & POLLIN) {
handle_new_connection(fd);
}
}
@@ -199,7 +197,7 @@ int osaf_auth_server_create(const char *
client_auth_data_callback = callback;
// create server socket
- int *fd = malloc(sizeof(int));
+ int *fd = calloc(1, sizeof(int));
*fd = server_sock_create(pathname);
osafassert(pthread_attr_init(&attr) == 0);
@@ -219,45 +217,80 @@ int osaf_auth_server_create(const char *
/* used by server, logging is OK */
bool osaf_user_is_member_of_group(uid_t uid, const char *groupname)
{
- int res;
- char **member;
- struct group grp;
- struct group *result;
- char grpmembuf[16384]; // can use sysconf(_SC_GETPW_R_SIZE_MAX)
-
- // get group file entry with list of member user names
- res = getgrnam_r(groupname, &grp, grpmembuf, sizeof(grpmembuf),
&result);
- if (res > 0) {
- LOG_ER("%s: get group file entry failed for '%s' - %s",
- __FUNCTION__, groupname, strerror(res));
+ long grpmembufsize = sysconf(_SC_GETGR_R_SIZE_MAX);
+ if (grpmembufsize < 0) grpmembufsize = 16384;
+ char* grpmembuf = malloc(grpmembufsize);
+ if (grpmembuf == NULL) {
+ LOG_ER("%s: Failed to allocate %ld bytes",
+ __FUNCTION__, grpmembufsize);
return false;
}
- if (result == NULL) {
+ long pwdmembufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
+ if (pwdmembufsize < 0) pwdmembufsize = 16384;
+ char* pwdmembuf = malloc(pwdmembufsize);
+ if (pwdmembuf == NULL) {
+ LOG_ER("%s: Failed to allocate %ld bytes",
+ __FUNCTION__, pwdmembufsize);
+ free(grpmembuf);
+ return false;
+ }
+
+ // get group file entry with list of member user names
+ struct group gbuf;
+ struct group *client_grp;
+ int grnam_retval = getgrnam_r(groupname, &gbuf, grpmembuf,
grpmembufsize, &client_grp);
+ if (grnam_retval != 0) {
+ LOG_ER("%s: get group file entry failed for '%s' - %s",
+ __FUNCTION__, groupname, strerror(grnam_retval));
+ free(pwdmembuf);
+ free(grpmembuf);
+ return false;
+ }
+ if (client_grp == NULL) {
LOG_ER("%s: group '%s' does not exist", __FUNCTION__,
groupname);
+ free(pwdmembuf);
+ free(grpmembuf);
return false;
}
// get password file entry for user
- errno = 0;
- struct passwd *client_pwd = getpwuid(uid);
+ struct passwd pbuf;
+ struct passwd *client_pwd;
+ int pwuid_retval = getpwuid_r(uid, &pbuf, pwdmembuf, pwdmembufsize,
&client_pwd);
+ if (pwuid_retval != 0) {
+ LOG_WA("%s: get password file entry failed for uid=%u - %s",
+ __FUNCTION__, (unsigned) uid, strerror(pwuid_retval));
+ free(pwdmembuf);
+ free(grpmembuf);
+ return false;
+ }
if (client_pwd == NULL) {
- LOG_WA("%s: get password file entry failed for uid=%d - %s",
- __FUNCTION__, uid, strerror(errno));
+ LOG_WA("%s: user id %u does not exist", __FUNCTION__,
(unsigned) uid);
+ free(pwdmembuf);
+ free(grpmembuf);
return false;
}
// check the primary group of the user
- if (client_pwd->pw_gid == grp.gr_gid)
+ if (client_pwd->pw_gid == client_grp->gr_gid) {
+ free(pwdmembuf);
+ free(grpmembuf);
return true;
+ }
/* loop list of usernames that are members of the group trying find a
* match with the specified user name */
- for (member = grp.gr_mem; *member != NULL; member++) {
- if (strcmp(client_pwd->pw_name, *member) == 0)
+ for (char **member = client_grp->gr_mem; *member != NULL; member++) {
+ if (strcmp(client_pwd->pw_name, *member) == 0) {
+ free(pwdmembuf);
+ free(grpmembuf);
return true;
+ }
}
+ free(pwdmembuf);
+ free(grpmembuf);
return false;
}
@@ -267,7 +300,7 @@ int osaf_auth_server_connect(const char
int timeout)
{
int sock_fd, len;
- struct sockaddr_un remote;
+ struct sockaddr_un remote = { 0 };
TRACE_ENTER();
@@ -291,10 +324,7 @@ int osaf_auth_server_connect(const char
goto done;
}
- struct pollfd fds;
- fds.fd = sock_fd;
- fds.events = POLLIN;
-
+ struct pollfd fds = { .fd = sock_fd, .events = POLLIN, .revents = 0 };
int res = osaf_poll(&fds, 1, timeout);
if (res == 0) {
@@ -325,95 +355,54 @@ done:
return len;
}
-int osaf_get_group_list(const uid_t uid, const gid_t gid, gid_t *groups, int
*ngroups)
+int osaf_getgrouplist(const char* user, gid_t group, gid_t* groups, int*
ngroups)
{
- int rc = -1; // Initially set to error
+
+ char* gr_buf = NULL;
+ size_t gr_bufsize = 4096;
+ struct group gbuf;
+ struct group* gr;
int size = 0;
- int max_groups = sysconf(_SC_NGROUPS_MAX);
- if (max_groups == -1){
- LOG_ER("Could not get NGROUPS_MAX, %s",strerror(errno));
- }
- if (!ngroups){
- LOG_ER("ngroups must not be NULL");
- return -1;
- }
+ if (size < *ngroups) groups[size] = group;
+ ++size;
- if (*ngroups > max_groups){
- LOG_ER("nGroups greater than NGROUPS_MAX");
- return -1;
- }
-
- if (groups){
- groups[size] = gid;
- }
- /* User always belong to at least one group */
- size++;
-
- struct passwd *pwd = getpwuid(uid);
- if (!pwd){
- LOG_ER("Could not getpwnam of user %d, %s", uid,
strerror(errno));
- return -1;
- }
-
- /* Reset entry to beginning */
- errno = 0;
setgrent();
- /* setgrent() sometimes returns ENOENT on UML
- * Explicitly treats it as not an error */
- if (errno != 0 && errno != ENOENT) {
- LOG_NO("setgrent failed: %s", strerror(errno));
- return -1;
- }
-
- errno = 0;
- struct group *gr = getgrent();
- if (errno != 0) {
- LOG_NO("setgrent failed: %s", strerror(errno));
- goto done;
- }
-
- while (gr){
- if (gr->gr_gid == gid){
- errno = 0;
- gr = getgrent();
- if (errno != 0) {
- LOG_NO("setgrent failed: %s", strerror(errno));
- goto done;
- }
- continue;
- }
-
- int i = 0;
- for (i = 0; gr->gr_mem[i]; i++){
- if(strcmp(gr->gr_mem[i], pwd->pw_name) == 0){
- /* Found matched group */
- if ((groups) && (size < *ngroups)){
- groups[size] = gr->gr_gid;
+ while ((gr = osaf_getgrent_r(&gbuf, &gr_buf, &gr_bufsize)) != NULL) {
+ if (gr->gr_gid != group) {
+ for (int i = 0; gr->gr_mem[i] != NULL; ++i) {
+ if (strcmp(gr->gr_mem[i], user) == 0) {
+ if (size < *ngroups) groups[size] =
gr->gr_gid;
+ ++size;
+ break;
}
- size++;
- break;
}
}
- errno = 0;
- gr = getgrent();
- if (errno != 0) {
- LOG_NO("setgrent failed: %s", strerror(errno));
- goto done;
+ }
+ endgrent();
+ free(gr_buf);
+
+ int result = size <= *ngroups ? size : -1;
+ *ngroups = size;
+ return result;
+}
+
+static struct group* osaf_getgrent_r(struct group *gbuf, char** buf,
+ size_t* buflen)
+{
+ struct group* gbufp = NULL;
+ if (*buf == NULL) *buf = malloc(*buflen);
+ for (;;) {
+ if (*buf == NULL) {
+ LOG_ER("could not allocate %zu bytes", *buflen);
+ break;
}
+ int result = getgrent_r(gbuf, *buf, *buflen, &gbufp);
+ if (result != ERANGE) break;
+ *buflen *= 2;
+ char* new_buf = realloc(*buf, *buflen);
+ if (new_buf == NULL) free(*buf);
+ *buf = new_buf;
}
-
- // rc will be set to non-error value
- if (groups){
- *ngroups = (size < *ngroups)? size : *ngroups;
- rc = size;
- } else {
- *ngroups = size;
- rc = 0;
- }
-
-done:
- endgrent();
-
- return rc;
+ return gbufp;
}
diff --git a/osaf/libs/core/common/osaf_timerfd.c
b/osaf/libs/core/common/osaf_timerfd.c
--- a/osaf/libs/core/common/osaf_timerfd.c
+++ b/osaf/libs/core/common/osaf_timerfd.c
@@ -19,6 +19,7 @@
#define _GNU_SOURCE
#endif
#include "osaf_timerfd.h"
+#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <pthread.h>
@@ -181,6 +182,7 @@ int osaf_timerfd_create(clockid_t clock_
timer->write_socket = sfd[1];
struct sigevent event;
+ memset(&event, 0, sizeof(event));
event.sigev_notify = SIGEV_THREAD;
event.sigev_value.sival_int = timer->sequence_no;
event.sigev_notify_function = EventHandler;
diff --git a/osaf/libs/core/cplusplus/base/tests/time_compare_test.cc
b/osaf/libs/core/cplusplus/base/tests/time_compare_test.cc
--- a/osaf/libs/core/cplusplus/base/tests/time_compare_test.cc
+++ b/osaf/libs/core/cplusplus/base/tests/time_compare_test.cc
@@ -22,11 +22,15 @@ static const timespec kZeroDotNineSecond
static const timespec kOneDotOneSeconds = { 1, 100000000 };
TEST(BaseTimeCompare, ZeroWithZero) {
+ // cppcheck-suppress duplicateExpression
EXPECT_FALSE(base::kZeroSeconds < base::kZeroSeconds);
+ // cppcheck-suppress duplicateExpression
EXPECT_TRUE(base::kZeroSeconds <= base::kZeroSeconds);
EXPECT_TRUE(base::kZeroSeconds == base::kZeroSeconds);
EXPECT_FALSE(base::kZeroSeconds != base::kZeroSeconds);
+ // cppcheck-suppress duplicateExpression
EXPECT_TRUE(base::kZeroSeconds >= base::kZeroSeconds);
+ // cppcheck-suppress duplicateExpression
EXPECT_FALSE(base::kZeroSeconds > base::kZeroSeconds);
}
@@ -67,11 +71,15 @@ TEST(BaseTimeCompare, OneWithZero) {
}
TEST(BaseTimeCompare, OneWithOne) {
+ // cppcheck-suppress duplicateExpression
EXPECT_FALSE(base::kOneSecond < base::kOneSecond);
+ // cppcheck-suppress duplicateExpression
EXPECT_TRUE(base::kOneSecond <= base::kOneSecond);
EXPECT_TRUE(base::kOneSecond == base::kOneSecond);
EXPECT_FALSE(base::kOneSecond != base::kOneSecond);
+ // cppcheck-suppress duplicateExpression
EXPECT_TRUE(base::kOneSecond >= base::kOneSecond);
+ // cppcheck-suppress duplicateExpression
EXPECT_FALSE(base::kOneSecond > base::kOneSecond);
}
@@ -94,11 +102,15 @@ TEST(BaseTimeCompare, OneDotOneWithOne)
}
TEST(BaseTimeCompare, ZeroDotNineWithZeroDotNine) {
+ // cppcheck-suppress duplicateExpression
EXPECT_FALSE(kZeroDotNineSeconds < kZeroDotNineSeconds);
+ // cppcheck-suppress duplicateExpression
EXPECT_TRUE(kZeroDotNineSeconds <= kZeroDotNineSeconds);
EXPECT_TRUE(kZeroDotNineSeconds == kZeroDotNineSeconds);
EXPECT_FALSE(kZeroDotNineSeconds != kZeroDotNineSeconds);
+ // cppcheck-suppress duplicateExpression
EXPECT_TRUE(kZeroDotNineSeconds >= kZeroDotNineSeconds);
+ // cppcheck-suppress duplicateExpression
EXPECT_FALSE(kZeroDotNineSeconds > kZeroDotNineSeconds);
}
diff --git a/osaf/libs/core/include/ncspatricia.h
b/osaf/libs/core/include/ncspatricia.h
--- a/osaf/libs/core/include/ncspatricia.h
+++ b/osaf/libs/core/include/ncspatricia.h
@@ -52,9 +52,6 @@ extern "C" {
typedef struct ncs_patricia_params {
int key_size; /* 1..NCS_PATRICIA_MAX_KEY_SIZE - in OCTETS */
- int info_size; /* NOT USED! Present for
backward-compatibility only! */
- int actual_key_size; /* NOT USED! Present for
backward-compatibility only! */
- int node_size; /* NOT USED! Present for backward
compatibitity only! */
} NCS_PATRICIA_PARAMS;
#define NCS_PATRICIA_MAX_KEY_SIZE 600 /* # octets */
diff --git a/osaf/libs/core/leap/hj_edp.c b/osaf/libs/core/leap/hj_edp.c
--- a/osaf/libs/core/leap/hj_edp.c
+++ b/osaf/libs/core/leap/hj_edp.c
@@ -166,7 +166,6 @@ uint32_t ncs_edp_uns8(EDU_HDL *hdl, EDU_
{
uint8_t *p8;
uint8_t u8 = 0x00;
- uint16_t len = 0;
#if(NCS_EDU_VERBOSE_PRINT == 1)
uint32_t i = 0;
#endif
@@ -209,7 +208,7 @@ uint32_t ncs_edp_uns8(EDU_HDL *hdl, EDU_
{
uint8_t *uptr = NULL;
- len = 1; /* default */
+ uint16_t len = 1; /* default */
if (!buf_env->is_ubaid) {
/* Look into length of the Octet-stream first.
*/
p8 = (uint8_t *)buf_env->info.tlv_env.cur_bufp;
@@ -349,7 +348,7 @@ uint32_t ncs_edp_uns16(EDU_HDL *hdl, EDU
uint32_t *ptr_data_len, EDU_BUF_ENV *buf_env, EDP_OP_TYPE
op, EDU_ERR *o_err)
{
uint8_t *p8;
- uint16_t u16, len = 1, byte_cnt = 0;
+ uint16_t u16;
switch (op) {
case EDP_OP_TYPE_ENC:
@@ -369,7 +368,7 @@ uint32_t ncs_edp_uns16(EDU_HDL *hdl, EDU
*ptr_data_len = 1;
}
/* "*ptr_data_len" instances of "uns16" to be encoded */
- byte_cnt = (uint16_t)ncs_encode_tlv_n_16bit(&p8,
(uint16_t *)ptr, (uint16_t)*ptr_data_len);
+ uint16_t byte_cnt = (uint16_t)
ncs_encode_tlv_n_16bit(&p8, (uint16_t*) ptr, (uint16_t) *ptr_data_len);
ncs_edu_skip_space(&buf_env->info.tlv_env, byte_cnt);
#if(NCS_EDU_VERBOSE_PRINT == 1)
memset(&gl_log_string, '\0', GL_LOG_STRING_LEN);
@@ -382,7 +381,7 @@ uint32_t ncs_edp_uns16(EDU_HDL *hdl, EDU
{
uint16_t *uptr = NULL;
- len = 1; /* default */
+ uint16_t len = 1; /* default */
if (!buf_env->is_ubaid) {
/* Look into length of the Octet-stream first.
*/
p8 = (uint8_t *)buf_env->info.tlv_env.cur_bufp;
@@ -775,7 +774,7 @@ uint32_t ncs_edp_string(EDU_HDL *hdl, ED
uint32_t *ptr_data_len, EDU_BUF_ENV *buf_env, EDP_OP_TYPE
op, EDU_ERR *o_err)
{
uint8_t *p8, *src_p8;
- uint16_t len = 0, byte_cnt = 0;
+ uint16_t len = 0;
switch (op) {
case EDP_OP_TYPE_ENC:
@@ -794,7 +793,7 @@ uint32_t ncs_edp_string(EDU_HDL *hdl, ED
}
} else {
p8 = (uint8_t *)buf_env->info.tlv_env.cur_bufp;
- byte_cnt = (uint16_t)ncs_encode_tlv_n_octets(&p8,
src_p8, (uint8_t)len);
+ uint16_t byte_cnt = (uint16_t)
ncs_encode_tlv_n_octets(&p8, src_p8, (uint8_t) len);
ncs_edu_skip_space(&buf_env->info.tlv_env, byte_cnt);
}
#if(NCS_EDU_VERBOSE_PRINT == 1)
@@ -1658,7 +1657,7 @@ uint32_t ncs_edp_uns64(EDU_HDL *hdl, EDU
if (*(uint64_t **)ptr == NULL) {
/* Since "uns64" is the responsibility of LEAP, LEAP
is supposed to malloc this memory. */
- (*(uint64_t **)ptr) = uptr = malloc((sizeof(uint64_t) /
sizeof(uint8_t))*sizeof(uint8_t));
+ (*(uint64_t**) ptr) = uptr = malloc(sizeof(uint64_t));
if (uptr == NULL) {
/* Memory failure. */
*o_err = EDU_ERR_MEM_FAIL;
@@ -1810,7 +1809,7 @@ uint32_t ncs_edp_int64(EDU_HDL *hdl, EDU
if (*(int64_t **)ptr == NULL) {
/* Since "int64" is the responsibility of LEAP, LEAP
is supposed to malloc this memory. */
- (*(int64_t **)ptr) = uptr = malloc((sizeof(int64_t) /
sizeof(uint8_t))*sizeof(uint8_t));
+ (*(int64_t**) ptr) = uptr = malloc(sizeof(int64_t));
if (uptr == NULL) {
/* Memory failure. */
*o_err = EDU_ERR_MEM_FAIL;
diff --git a/osaf/libs/core/leap/hj_edu.c b/osaf/libs/core/leap/hj_edu.c
--- a/osaf/libs/core/leap/hj_edu.c
+++ b/osaf/libs/core/leap/hj_edu.c
@@ -129,7 +129,6 @@ uint32_t ncs_edu_ver_exec(EDU_HDL *edu_h
{
uint32_t rc = NCSCC_RC_SUCCESS, lcl_cnt = 0;
EDU_BUF_ENV lcl_edu_buf;
- va_list arguments; /* A place to store the list of arguments */
int *var_array = NULL;
/* Error checks done here. */
@@ -194,6 +193,7 @@ uint32_t ncs_edu_ver_exec(EDU_HDL *edu_h
var_array = malloc(var_cnt*sizeof(int));
+ va_list arguments;
va_start(arguments, var_cnt);
for (x = 0; x < var_cnt; x++) {
var_array[x] = va_arg(arguments, int);
@@ -410,9 +410,8 @@ uint32_t ncs_edu_run_edp(EDU_HDL *edu_hd
{
NCSCONTEXT lcl_ptr = NULL;
EDU_HDL_NODE *lcl_hdl_node = NULL;
- uint32_t lcl_rc = NCSCC_RC_SUCCESS, dtype_attrb = 0x00000000;
- NCS_EDU_ADMIN_OP_INFO admin_op;
- uint32_t next_offset = 0, cnt = 0; /* for linked list */
+ uint32_t lcl_rc = NCSCC_RC_SUCCESS;
+ uint32_t next_offset = 0; /* for linked list */
uint8_t *p8, u8 = 0;
uint16_t u16 = 0;
@@ -434,14 +433,17 @@ uint32_t ncs_edu_run_edp(EDU_HDL *edu_hd
|| (optype == EDP_OP_TYPE_PP)
#endif
) {
+ uint32_t cnt = 0;
/* Lookup data-type attributes, and if it's a linked-list/array,
run the loop here. */
- dtype_attrb = lcl_hdl_node->attrb;
+ uint32_t dtype_attrb = lcl_hdl_node->attrb;
/* Now that dtype_attrb got filled, compare it with expected
values. */
if ((dtype_attrb & EDQ_LNKLIST) == EDQ_LNKLIST) {
/* Get next_offset. */
+ NCS_EDU_ADMIN_OP_INFO admin_op;
+ memset(&admin_op, 0, sizeof(admin_op));
admin_op.adm_op_type =
NCS_EDU_ADMIN_OP_TYPE_GET_LL_NEXT_OFFSET;
admin_op.info.get_ll_offset.o_next_offset =
&next_offset;
edp(edu_hdl, edu_tkn, (NCSCONTEXT)&admin_op, NULL,
NULL, EDP_OP_TYPE_ADMIN, o_err);
@@ -494,9 +496,6 @@ uint32_t ncs_edu_run_edp(EDU_HDL *edu_hd
}
} else {
/* Encode/Admin operations */
- if (optype == EDP_OP_TYPE_ADMIN) {
- admin_op = *((NCS_EDU_ADMIN_OP_INFO *)ptr);
- }
lcl_rc = edp(edu_hdl, edu_tkn, ptr, dcnt, buf_env, optype,
o_err);
}
@@ -2475,7 +2474,7 @@ uint32_t ncs_edu_validate_and_gen_test_i
for (i = 0; ((i != instr_count) && (rules_head[i].instr != EDU_END));
i++) {
if (rules_head[i].instr == EDU_TEST) {
- bool already_added = false, lclfnd = false;
+ bool already_added = false;
/* If already in the "*head" list, just increment the
"refcount"
of that entry. */
@@ -2488,6 +2487,7 @@ uint32_t ncs_edu_validate_and_gen_test_i
}
}
if (!already_added) {
+ bool lclfnd = false;
/* Verify whether there exists an "EDU_EXEC"
instruction
with offset matching "rules_head[i].fld5",
and EDP value
matching "rules_head[i].fld1". If yes, then
only this
@@ -2525,7 +2525,7 @@ uint32_t ncs_edu_validate_and_gen_test_i
} /* if(!already_added) */
} /* if(rules_head[i].instr == EDU_TEST) */
else if (rules_head[i].instr == EDU_EXEC) {
- bool already_added = false, lcl_to_be_added = false;
+ bool lcl_to_be_added = false;
for (j = 0; (((j != instr_count) && rules_head[j].instr
!= EDU_END)); j++) {
if (rules_head[j].instr == EDU_EXEC) {
@@ -2540,6 +2540,7 @@ uint32_t ncs_edu_validate_and_gen_test_i
}
}
if (lcl_to_be_added) {
+ bool already_added = false;
/* Lookup "fld6" offset in the structure, and
store the instruction
as a test-able field */
for (tmp = *head; (tmp != NULL); tmp =
tmp->next) {
@@ -3241,11 +3242,12 @@ bool ncs_edu_return_builtin_edp_size(EDU
*****************************************************************************/
uint32_t ncs_edu_compile_edp(EDU_HDL *edu_hdl, EDU_PROG_HANDLER prog,
EDU_HDL_NODE **hdl_node, EDU_ERR *o_err)
{
- EDU_HDL_NODE *lcl_hdl_node = NULL, *new_node = NULL;
+ EDU_HDL_NODE *lcl_hdl_node = NULL;
/* If hdl_node entry not present, add now. */
if ((lcl_hdl_node = (EDU_HDL_NODE *)
ncs_patricia_tree_get(&edu_hdl->tree, (uint8_t *)&prog)) == NULL) {
+ EDU_HDL_NODE* new_node;
if ((lcl_hdl_node = (new_node = (EDU_HDL_NODE *)
malloc(sizeof(EDU_HDL_NODE)))) == NULL) {
*o_err = EDU_ERR_MEM_FAIL;
return NCSCC_RC_FAILURE;
@@ -3289,12 +3291,8 @@ uint32_t ncs_edu_compile_edp(EDU_HDL *ed
*****************************************************************************/
uint32_t ncs_edu_hdl_init(EDU_HDL *edu_hdl)
{
- NCS_PATRICIA_PARAMS list_params;
-
memset(edu_hdl, '\0', sizeof(EDU_HDL));
- /* Init the tree first */
- list_params.key_size = sizeof(EDU_PROG_HANDLER);
- /* list_params.info_size = 0; */
+ NCS_PATRICIA_PARAMS list_params = { .key_size =
sizeof(EDU_PROG_HANDLER) };
if ((ncs_patricia_tree_init(&edu_hdl->tree, &list_params))
!= NCSCC_RC_SUCCESS) {
return m_LEAP_DBG_SINK(NCSCC_RC_FAILURE);
@@ -3318,13 +3316,13 @@ uint32_t ncs_edu_hdl_init(EDU_HDL *edu_h
*****************************************************************************/
uint32_t ncs_edu_hdl_flush(EDU_HDL *edu_hdl)
{
- EDU_PROG_HANDLER lcl_key, *key = NULL;
- NCS_PATRICIA_NODE *pnode = NULL;
-
if (edu_hdl->is_inited == true) {
+ EDU_PROG_HANDLER lcl_key, *key = NULL;
for (;;) {
+ NCS_PATRICIA_NODE *pnode;
if ((pnode = ncs_patricia_tree_getnext(&edu_hdl->tree,
(const uint8_t *)key)) != NULL) {
/* Store the key for the next getnext call */
+ // cppcheck-suppress unreadVariable
lcl_key = ((EDU_HDL_NODE *)pnode)->edp;
key = &lcl_key;
@@ -3444,7 +3442,7 @@ uint32_t ncs_encode_tlv_16bit(uint8_t **
*****************************************************************************/
uint32_t ncs_encode_tlv_n_16bit(uint8_t **stream, uint16_t *val_ptr, uint16_t
n_count)
{
- uint16_t lcnt = 0, len = n_count, val = 0;
+ uint16_t lcnt = 0, len = n_count;
if (n_count == 0)
return 0;
@@ -3453,7 +3451,7 @@ uint32_t ncs_encode_tlv_n_16bit(uint8_t
*(*stream)++ = (uint8_t)(len >> 8); /* length */
*(*stream)++ = (uint8_t)len; /* length */
for (; lcnt < n_count; lcnt++) {
- val = *val_ptr;
+ uint16_t val = *val_ptr;
*(*stream)++ = (uint8_t)(val >> 8);
*(*stream)++ = (uint8_t)(val);
val_ptr++;
@@ -3496,7 +3494,6 @@ uint32_t ncs_encode_tlv_32bit(uint8_t **
uint32_t ncs_encode_tlv_n_32bit(uint8_t **stream, uint32_t *val_ptr, uint16_t
n_count)
{
uint16_t lcnt = 0, len = n_count;
- uint32_t val = 0;
if (n_count == 0)
return 0;
@@ -3505,7 +3502,7 @@ uint32_t ncs_encode_tlv_n_32bit(uint8_t
*(*stream)++ = (uint8_t)(len >> 8); /* length */
*(*stream)++ = (uint8_t)len; /* length */
for (; lcnt < n_count; lcnt++) {
- val = *val_ptr;
+ uint32_t val = *val_ptr;
*(*stream)++ = (uint8_t)(val >> 24);
*(*stream)++ = (uint8_t)(val >> 16);
*(*stream)++ = (uint8_t)(val >> 8);
@@ -3526,7 +3523,6 @@ uint32_t ncs_encode_tlv_n_32bit(uint8_t
*****************************************************************************/
uint32_t ncs_encode_tlv_n_octets(uint8_t **stream, uint8_t *val, uint16_t
count)
{
- int i;
uint16_t lcnt = count;
*(*stream)++ = (uint8_t)(NCS_EDU_FMAT_OCT); /* type */
@@ -3538,7 +3534,7 @@ uint32_t ncs_encode_tlv_n_octets(uint8_t
return (uint32_t)EDU_TLV_HDR_SIZE;
}
- for (i = 0; i < count; i++)
+ for (int i = 0; i < count; i++)
*(*stream)++ = *val++;
}
return (uint32_t)(EDU_TLV_HDR_SIZE + count);
@@ -3623,7 +3619,6 @@ uint32_t ncs_decode_tlv_32bit(uint8_t **
*****************************************************************************/
uint16_t ncs_decode_tlv_n_32bit(uint8_t **stream, uint32_t *dest)
{
- uint32_t val = 0; /* Accumulator */
uint16_t lcnt = 0, len = 0;
(*stream)++; /* type */
@@ -3632,7 +3627,7 @@ uint16_t ncs_decode_tlv_n_32bit(uint8_t
len |= (uint16_t)*(*stream)++;
for (; lcnt < len; lcnt++) {
- val = (uint32_t)*(*stream)++ << 24;
+ uint32_t val = (uint32_t)*(*stream)++ << 24;
val |= (uint32_t)*(*stream)++ << 16;
val |= (uint32_t)*(*stream)++ << 8;
val |= (uint32_t)*(*stream)++;
@@ -3676,7 +3671,6 @@ uint16_t ncs_decode_tlv_16bit(uint8_t **
*****************************************************************************/
uint16_t ncs_decode_tlv_n_16bit(uint8_t **stream, uint16_t *dest)
{
- uint16_t val = 0; /* Accumulator */
uint16_t lcnt = 0, len = 0;
(*stream)++; /* type */
@@ -3685,7 +3679,7 @@ uint16_t ncs_decode_tlv_n_16bit(uint8_t
len |= (uint16_t)*(*stream)++;
for (; lcnt < len; lcnt++) {
- val = (uint16_t)((uint16_t)*(*stream)++ << 8);
+ uint16_t val = (uint16_t)((uint16_t)*(*stream)++ << 8);
val |= (uint16_t)*(*stream)++;
/* Convert to host-order and Write it back */
dest[lcnt] = val;
diff --git a/osaf/libs/core/leap/hj_enc.c b/osaf/libs/core/leap/hj_enc.c
--- a/osaf/libs/core/leap/hj_enc.c
+++ b/osaf/libs/core/leap/hj_enc.c
@@ -55,7 +55,6 @@
USRBUF *ncs_encode_n_octets(USRBUF *u, uint8_t *os, unsigned int count)
{
- uint8_t *p;
unsigned int remaining = count;
unsigned int offset = 0;
@@ -65,6 +64,7 @@ USRBUF *ncs_encode_n_octets(USRBUF *u, u
count = remaining;
do {
+ uint8_t *p;
if ((p = m_MMGR_RESERVE_AT_END(&u, count, uint8_t *)) !=
(uint8_t *)0) {
/*
* Build the octet string...Remember a NULL pointer
diff --git a/osaf/libs/core/leap/hj_hdl.c b/osaf/libs/core/leap/hj_hdl.c
--- a/osaf/libs/core/leap/hj_hdl.c
+++ b/osaf/libs/core/leap/hj_hdl.c
@@ -176,7 +176,6 @@ uint32_t ncshm_init(void)
{
/* Hdl Mgr does bit-fields; here we do a few exercises up front to make
*/
/* sure YOUR target system can cope with bit-stuff we do...............
*/
- HM_HDL ha;
HM_HDL hb;
HM_HDL *p_hdl;
uint32_t *p_temp;
@@ -190,10 +189,12 @@ uint32_t ncshm_init(void)
assert(sizeof(uint32_t) == sizeof(HM_HDL)); /* must be same size */
- ha.idx1 = 1; /* make up a fake handle with values */
- ha.idx2 = 2;
- ha.idx3 = 3;
- ha.seq_id = 6;
+ HM_HDL ha = {
+ .seq_id = 6,
+ .idx1 = 1, /* make up a fake handle with values */
+ .idx2 = 2,
+ .idx3 = 3
+ };
/* cast to INT PTR, to HDL PTR, deref to HDL; bit-fields still stable ?
*/
@@ -228,7 +229,6 @@ uint32_t ncshm_init(void)
void ncshm_delete(void)
{
uint32_t i, j;
- HM_UNIT *unit;
gl_im_created--;
if (gl_im_created > 0)
@@ -242,6 +242,7 @@ void ncshm_delete(void)
}
for (i = 0; i < HM_UNIT_CNT; i++) {
+ HM_UNIT *unit;
if ((unit = gl_hm.unit[i]) != NULL) {
for (j = 0; j < HM_BANK_CNT; j++) {
if (unit->cells[j] != NULL)
@@ -268,7 +269,6 @@ void ncshm_delete(void)
uint32_t ncshm_create_hdl(uint8_t pool, NCS_SERVICE_ID id, NCSCONTEXT save)
{
HM_FREE *free;
- HM_CELL *cell;
uint32_t ret = 0;
if (pool >= HM_POOL_CNT)
@@ -277,7 +277,7 @@ uint32_t ncshm_create_hdl(uint8_t pool,
m_NCS_LOCK(&gl_hm.lock[pool], NCS_LOCK_WRITE);
if ((free = hm_alloc_cell(pool)) != NULL) {
- cell = hm_find_cell(&free->hdl); /* These two lines are
sanity */
+ HM_CELL* cell = hm_find_cell(&free->hdl); /* These two
lines are sanity */
assert(((void *)free == (void *)cell)); /* checks that add no
value */
ret = (*(uint32_t *)&free->hdl);
@@ -544,8 +544,6 @@ uint32_t hm_make_free_cells(HM_PMGR *pmg
{
HM_UNIT *unit;
HM_CELLS *cells;
- HM_CELL *cell;
- HM_HDL hdl;
uint32_t i;
unit = gl_hm.unit[pmgr->curr];
@@ -575,15 +573,18 @@ uint32_t hm_make_free_cells(HM_PMGR *pmg
memset(cells, 0, sizeof(HM_CELLS));
- hdl.idx1 = pmgr->curr; /* set handle conditions */
- hdl.idx2 = unit->curr;
- hdl.seq_id = 0;
+ HM_HDL hdl = {
+ .seq_id = 0,
+ .idx1 = pmgr->curr, /* set handle conditions */
+ .idx2 = unit->curr,
+ .idx3 = 0
+ };
unit->cells[unit->curr++] = cells; /* update curr++ for next time
*/
for (i = 0; i < HM_CELL_CNT; i++) { /* carve um up and put in
free-po0l */
hdl.idx3 = i;
- cell = &(cells->cell[i]);
+ HM_CELL* cell = &(cells->cell[i]);
hm_free_cell(cell, &hdl, false);
}
diff --git a/osaf/libs/core/leap/hj_tmr.c b/osaf/libs/core/leap/hj_tmr.c
--- a/osaf/libs/core/leap/hj_tmr.c
+++ b/osaf/libs/core/leap/hj_tmr.c
@@ -386,12 +386,11 @@ uint32_t ncs_rp_tmr_stop(NCS_RP_TMR_CB *
**************************************************************************/
uint32_t ncs_rp_tmr_delete(NCS_RP_TMR_CB *tmr_cb, NCS_RP_TMR_HDL tmr_id)
{
- NCS_RP_TMR_INFO *tmr_info;
uint32_t res = NCSCC_RC_SUCCESS;
m_NCS_LOCK(&tmr_cb->tmr_lock, NCS_LOCK_WRITE);
do {
- tmr_info = (NCS_RP_TMR_INFO *)tmr_id;
+ NCS_RP_TMR_INFO* tmr_info = (NCS_RP_TMR_INFO *)tmr_id;
if (tmr_info == NULL) {
m_RP_TMR_LOG_MSG("ncs_rp_tmr_delete timer is not
started already", tmr_info);
res = NCSCC_RC_FAILURE;
@@ -422,7 +421,6 @@ uint32_t ncs_rp_tmr_delete(NCS_RP_TMR_CB
uint32_t ncs_rp_tmr_destory(NCS_RP_TMR_CB **pptmr_cb)
{
NCS_RP_TMR_INFO *tmr_info;
- NCS_RP_TMR_INFO *pres_tmr_info;
NCS_RP_TMR_CB *tmr_cb = *pptmr_cb;
m_NCS_LOCK(&tmr_cb->tmr_lock, NCS_LOCK_WRITE);
@@ -436,7 +434,7 @@ uint32_t ncs_rp_tmr_destory(NCS_RP_TMR_C
m_NCS_TMR_DESTROY(tmr_cb->tmr_id);
/* remove all the buckets and node */
- pres_tmr_info = tmr_info;
+ NCS_RP_TMR_INFO* pres_tmr_info = tmr_info;
for (; tmr_info != NULL;) {
tmr_info = tmr_info->pnext;
free(pres_tmr_info);
@@ -468,7 +466,6 @@ uint32_t ncs_rp_tmr_destory(NCS_RP_TMR_C
uint32_t ncs_rp_tmr_exp(NCS_RP_TMR_CB *tmr_cb)
{
NCS_RP_TMR_INFO *tmr_list;
- NCS_RP_TMR_INFO *prev_tmr_info;
RP_TMR_CALLBACK call_back;
void *arg;
uint32_t tmr_diff = 0;
@@ -484,7 +481,7 @@ uint32_t ncs_rp_tmr_exp(NCS_RP_TMR_CB *t
m_RP_TMR_LOG_MSG("ncs_rp_tmr_exp received successfully", 0);
tmr_list = tmr_cb->start_list;
- prev_tmr_info = tmr_list;
+ NCS_RP_TMR_INFO* prev_tmr_info = tmr_list;
m_NCS_TMR_STOP(tmr_cb->tmr_id);
/* now OS timer is in active */
diff --git a/osaf/libs/core/leap/hj_ubaid.c b/osaf/libs/core/leap/hj_ubaid.c
--- a/osaf/libs/core/leap/hj_ubaid.c
+++ b/osaf/libs/core/leap/hj_ubaid.c
@@ -705,7 +705,6 @@ uint32_t ncs_uba_decode_pointer(NCS_UBAI
*****************************************************************************/
uint32_t ncs_encode_n_octets_in_uba(NCS_UBAID *uba, uint8_t *os, unsigned int
count)
{
- uint8_t *p;
uint32_t remaining;
uint32_t try_put;
@@ -733,7 +732,7 @@ uint32_t ncs_encode_n_octets_in_uba(NCS_
needs more than PAYLOAD_BUF_SIZE bytes anyway.
*/
try_put = remaining;
- p = m_MMGR_RESERVE_AT_END_AMAP(&(uba->ub), &try_put, uint8_t
*); /* Total=false, i.e. only as much as possible */
+ uint8_t* p = m_MMGR_RESERVE_AT_END_AMAP(&(uba->ub), &try_put,
uint8_t *); /* Total=false, i.e. only as much as possible */
if (p != NULL) {
/*
* Build the octet string...Remember a NULL pointer
diff --git a/osaf/libs/core/leap/os_defs.c b/osaf/libs/core/leap/os_defs.c
--- a/osaf/libs/core/leap/os_defs.c
+++ b/osaf/libs/core/leap/os_defs.c
@@ -502,7 +502,6 @@ uint32_t ncs_os_mq(NCS_OS_MQ_REQ_INFO *i
/* Create logic to-be-made more robust: Phani */
/* Create flag to-be-changed from 644 to something
better: Phani */
/* Check to-be-added to validate NCS_OS_MQ_MAX_PAYLOAD
limit: Phani */
- NCS_OS_MQ_HDL tmp_hdl;
info->info.create.o_hdl =
msgget(*info->info.create.i_key,
NCS_OS_MQ_PROTECTION_FLAGS | IPC_CREAT | IPC_EXCL);
@@ -511,7 +510,7 @@ uint32_t ncs_os_mq(NCS_OS_MQ_REQ_INFO *i
/* Queue already exists. We should start with
** a fresh queue. So let us delete this queue
*/
- tmp_hdl = msgget(*info->info.create.i_key,
NCS_OS_MQ_PROTECTION_FLAGS);
+ NCS_OS_MQ_HDL tmp_hdl =
msgget(*info->info.create.i_key, NCS_OS_MQ_PROTECTION_FLAGS);
if (msgctl(tmp_hdl, IPC_RMID, NULL) != 0) {
/* Queue deletion unsuccessful */
@@ -587,7 +586,7 @@ uint32_t ncs_os_posix_mq(NCS_OS_POSIX_MQ
case NCS_OS_POSIX_MQ_REQ_MSG_SEND_ASYNC:
{
- NCS_OS_MQ_REQ_INFO os_req;
+ NCS_OS_MQ_REQ_INFO os_req = { 0 };
if (req->req == NCS_OS_POSIX_MQ_REQ_MSG_SEND)
os_req.req = NCS_OS_MQ_REQ_MSG_SEND;
@@ -608,7 +607,7 @@ uint32_t ncs_os_posix_mq(NCS_OS_POSIX_MQ
case NCS_OS_POSIX_MQ_REQ_MSG_RECV_ASYNC:
{
- NCS_OS_MQ_REQ_INFO os_req;
+ NCS_OS_MQ_REQ_INFO os_req = { 0 };
if (req->req == NCS_OS_POSIX_MQ_REQ_MSG_RECV)
os_req.req = NCS_OS_MQ_REQ_MSG_RECV;
@@ -640,9 +639,8 @@ uint32_t ncs_os_posix_mq(NCS_OS_POSIX_MQ
break;
case NCS_OS_POSIX_MQ_REQ_OPEN:
{
- NCS_OS_MQ_REQ_INFO os_req;
+ NCS_OS_MQ_REQ_INFO os_req = { 0 };
NCS_OS_MQ_KEY key;
- FILE *file;
char filename[264];
struct msqid_ds buf;
@@ -653,7 +651,7 @@ uint32_t ncs_os_posix_mq(NCS_OS_POSIX_MQ
if (req->info.open.iflags & O_CREAT) {
os_req.req = NCS_OS_MQ_REQ_CREATE;
- file = fopen(filename, "w");
+ FILE* file = fopen(filename, "w");
if (file == NULL)
return NCSCC_RC_FAILURE;
@@ -689,7 +687,7 @@ uint32_t ncs_os_posix_mq(NCS_OS_POSIX_MQ
break;
case NCS_OS_POSIX_MQ_REQ_RESIZE:
{
- NCS_OS_MQ_REQ_INFO os_req;
+ NCS_OS_MQ_REQ_INFO os_req = { 0 };
os_req.req = NCS_OS_MQ_REQ_RESIZE;
os_req.info.resize.i_hdl = req->info.resize.mqd;
@@ -701,7 +699,7 @@ uint32_t ncs_os_posix_mq(NCS_OS_POSIX_MQ
break;
case NCS_OS_POSIX_MQ_REQ_CLOSE:
{
- NCS_OS_MQ_REQ_INFO os_req;
+ NCS_OS_MQ_REQ_INFO os_req = { 0 };
os_req.req = NCS_OS_MQ_REQ_DESTROY;
os_req.info.destroy.i_hdl = req->info.close.mqd;
@@ -770,7 +768,6 @@ static int32_t ncs_shm_prot_flags(uint32
uint32_t ncs_os_posix_shm(NCS_OS_POSIX_SHM_REQ_INFO *req)
{
- uint32_t prot_flag;
int32_t ret_flag;
uint64_t shm_size;
char shm_name[PATH_MAX];
@@ -807,7 +804,7 @@ uint32_t ncs_os_posix_shm(NCS_OS_POSIX_S
}
}
- prot_flag = ncs_shm_prot_flags(req->info.open.i_flags);
+ uint32_t prot_flag =
ncs_shm_prot_flags(req->info.open.i_flags);
req->info.open.o_addr =
mmap(req->info.open.o_addr, (size_t)shm_size /*
size_t == unsigned long */ ,
prot_flag, req->info.open.i_map_flags,
req->info.open.o_fd, req->info.open.i_offset);
diff --git a/osaf/libs/core/leap/sysf_exc_scr.c
b/osaf/libs/core/leap/sysf_exc_scr.c
--- a/osaf/libs/core/leap/sysf_exc_scr.c
+++ b/osaf/libs/core/leap/sysf_exc_scr.c
@@ -103,12 +103,12 @@ void ncs_exc_mdl_stop_timer(SYSF_PID_LIS
\**************************************************************************/
void ncs_exec_module_signal_hdlr(int signal)
{
- EXEC_MOD_INFO info;
-
if (signal == SIGCHLD) {
- info.pid = 0;
- info.status = 0;
- info.type = SYSF_EXEC_INFO_SIG_CHLD;
+ EXEC_MOD_INFO info = {
+ .pid = 0,
+ .status = 0,
+ .type = SYSF_EXEC_INFO_SIG_CHLD
+ };
/* printf("\n In SIGCHLD Handler \n"); */
@@ -140,12 +140,11 @@ void ncs_exec_module_signal_hdlr(int sig
\**************************************************************************/
void ncs_exec_module_timer_hdlr(void *uarg)
{
- EXEC_MOD_INFO info;
- int status = 0;
-
- info.pid = NCS_PTR_TO_INT32_CAST(uarg);
- info.status = status;
- info.type = SYSF_EXEC_INFO_TIME_OUT;
+ EXEC_MOD_INFO info = {
+ .pid = NCS_PTR_TO_INT32_CAST(uarg),
+ .status = 0,
+ .type = SYSF_EXEC_INFO_TIME_OUT
+ };
if(-1 == write(module_cb.write_fd, (const void *)&info,
sizeof(EXEC_MOD_INFO))){
@@ -398,11 +397,9 @@ uint32_t init_exec_mod_cb(void)
\**************************************************************************/
uint32_t start_exec_mod_cb(void)
{
- NCS_PATRICIA_PARAMS pt_params;
+ NCS_PATRICIA_PARAMS pt_params = { .key_size = sizeof(uint32_t) };
int spair[2];
- pt_params.key_size = sizeof(uint32_t);
-
if (ncs_patricia_tree_init(&module_cb.pid_list, &pt_params) !=
NCSCC_RC_SUCCESS) {
return m_LEAP_DBG_SINK(NCSCC_RC_FAILURE);
}
@@ -457,7 +454,6 @@ uint32_t start_exec_mod_cb(void)
\**************************************************************************/
uint32_t exec_mod_cb_destroy(void)
{
- SYSF_PID_LIST *exec_pid = NULL;
uint8_t pid = 0;
if (module_cb.init == true) {
@@ -471,6 +467,7 @@ uint32_t exec_mod_cb_destroy(void)
m_NCS_LOCK(&module_cb.tree_lock, NCS_LOCK_WRITE);
+ SYSF_PID_LIST* exec_pid;
while (NULL != (exec_pid = (SYSF_PID_LIST
*)ncs_patricia_tree_getnext(&module_cb.pid_list,
(const uint8_t *)&pid))) {
diff --git a/osaf/libs/core/leap/sysf_ipc.c b/osaf/libs/core/leap/sysf_ipc.c
--- a/osaf/libs/core/leap/sysf_ipc.c
+++ b/osaf/libs/core/leap/sysf_ipc.c
@@ -451,8 +451,6 @@ static uint32_t ipc_enqueue_ind_processi
\************************************************************************/
static uint32_t ipc_dequeue_ind_processing(NCS_IPC *ncs_ipc, unsigned int
active_queue)
{
- int inds_rmvd;
-
ncs_ipc->no_of_msgs[active_queue]--;
if (ncs_ipc->usr_counters[active_queue] != NULL)
@@ -461,7 +459,7 @@ static uint32_t ipc_dequeue_ind_processi
ncs_ipc->msg_count--;
if (ncs_ipc->msg_count == 0) {
- inds_rmvd = m_NCS_SEL_OBJ_RMV_IND(&ncs_ipc->sel_obj, true,
true);
+ int inds_rmvd = m_NCS_SEL_OBJ_RMV_IND(&ncs_ipc->sel_obj, true,
true);
if (inds_rmvd <= 0) {
if (inds_rmvd != -1) {
/* The object has not been destroyed and it has
no indication
diff --git a/osaf/libs/core/leap/sysf_mem.c b/osaf/libs/core/leap/sysf_mem.c
--- a/osaf/libs/core/leap/sysf_mem.c
+++ b/osaf/libs/core/leap/sysf_mem.c
@@ -851,22 +851,20 @@ char *sysf_reserve_at_end_amap(USRBUF **
void sysf_remove_from_end(USRBUF *pb, unsigned int size)
{
- USRBUF **pub;
USRBUF *ub;
- unsigned int buflen;
if (pb != BNULL) {
while ((size > 0) && (sysf_get_chain_len(pb))) {
/* Find the last one in the chain. */
- pub = (USRBUF **)NULL;
+ USRBUF** pub = (USRBUF**) NULL;
ub = pb;
while (ub->link != (USRBUF *)0) {
pub = &ub->link, ub = *pub;
}
- buflen = ub->count;
+ unsigned buflen = ub->count;
if (buflen > size) {
/* We can do the unappand without freeing any
buffers. */
ub->count -= size;
@@ -941,10 +939,9 @@ char *sysf_reserve_at_start(USRBUF **ppb
void sysf_remove_from_start(USRBUF **ppb, unsigned int size)
{
USRBUF *ub;
- unsigned int buflen;
while (((ub = *ppb) != (USRBUF *)0) && (size > 0)) {
- buflen = ub->count;
+ unsigned buflen = ub->count;
if (buflen > size) {
/* This is, like, simple. */
diff --git a/osaf/libs/core/leap/sysf_tmr.c b/osaf/libs/core/leap/sysf_tmr.c
--- a/osaf/libs/core/leap/sysf_tmr.c
+++ b/osaf/libs/core/leap/sysf_tmr.c
@@ -386,8 +386,6 @@ static uint32_t ncs_tmr_engine(struct ti
****************************************************************************/
static uint32_t ncs_tmr_wait(void)
{
-
- unsigned rc;
int inds_rmvd;
uint64_t next_delay = 0;
@@ -408,7 +406,7 @@ static uint32_t ncs_tmr_wait(void)
set.fd = m_GET_FD_FROM_SEL_OBJ(gl_tcb.sel_obj);
set.events = POLLIN;
osaf_timeval_to_timespec(&tv, &ts);
- rc = osaf_ppoll(&set, 1, next_delay != 0 ? &ts : NULL, NULL);
+ unsigned rc = osaf_ppoll(&set, 1, next_delay != 0 ? &ts : NULL,
NULL);
m_NCS_LOCK(&gl_tcb.safe.enter_lock, NCS_LOCK_WRITE);
if (rc == 1) {
@@ -542,7 +540,6 @@ bool sysfTmrCreate(void)
bool sysfTmrDestroy(void)
{
SYSF_TMR *tmr;
- SYSF_TMR *free_tmr;
SYSF_TMR_PAT_NODE *tmp = NULL;
/* There is only ever one timer per instance */
@@ -571,7 +568,7 @@ bool sysfTmrDestroy(void)
m_NCS_LOCK(&gl_tcb.safe.enter_lock, NCS_LOCK_WRITE);
tmr = &gl_tcb.safe.dmy_keep;
while (tmr->keep != NULL) {
- free_tmr = tmr->keep;
+ SYSF_TMR* free_tmr = tmr->keep;
tmr->keep = tmr->keep->keep;
m_NCS_MEM_FREE(free_tmr, NCS_MEM_REGION_PERSISTENT,
NCS_SERVICE_ID_LEAP_TMR, 0);
}
diff --git a/osaf/libs/core/leap/sysf_tsk.c b/osaf/libs/core/leap/sysf_tsk.c
--- a/osaf/libs/core/leap/sysf_tsk.c
+++ b/osaf/libs/core/leap/sysf_tsk.c
@@ -38,6 +38,7 @@
******************************************************************************
*/
+#include <string.h>
#include <ncsgl_defs.h>
#include "ncs_osprm.h"
@@ -48,6 +49,7 @@ ncs_task_create(NCS_OS_CB entry_pt,
void *arg, const char *name, unsigned int priority, int policy,
unsigned int stack_size_in_bytes, void **task_handle)
{
NCS_OS_TASK task;
+ memset(&task, 0, sizeof(task));
uint32_t rc;
task.info.create.i_entry_point = entry_pt;
@@ -68,6 +70,7 @@ ncs_task_create(NCS_OS_CB entry_pt,
uint32_t ncs_task_release(void *task_handle)
{
NCS_OS_TASK task;
+ memset(&task, 0, sizeof(task));
if (task_handle == NULL)
return NCSCC_RC_SUCCESS;
@@ -92,6 +95,7 @@ uint32_t ncs_task_join(void *task_handle
uint32_t ncs_task_detach(void *task_handle)
{
NCS_OS_TASK task;
+ memset(&task, 0, sizeof(task));
if (task_handle == NULL)
return NCSCC_RC_SUCCESS;
@@ -104,6 +108,7 @@ uint32_t ncs_task_detach(void *task_hand
uint32_t ncs_task_start(void *task_handle)
{
NCS_OS_TASK task;
+ memset(&task, 0, sizeof(task));
if (task_handle == NULL)
return NCSCC_RC_SUCCESS;
@@ -116,6 +121,7 @@ uint32_t ncs_task_start(void *task_handl
uint32_t ncs_task_stop(void *task_handle)
{
NCS_OS_TASK task;
+ memset(&task, 0, sizeof(task));
if (task_handle == NULL)
return NCSCC_RC_SUCCESS;
@@ -128,6 +134,7 @@ uint32_t ncs_task_stop(void *task_handle
uint32_t ncs_task_sleep(unsigned int delay_in_ms)
{
NCS_OS_TASK task;
+ memset(&task, 0, sizeof(task));
task.info.sleep.i_delay_in_ms = delay_in_ms;
diff --git a/osaf/libs/core/leap/tests/sysf_ipc_test.cc
b/osaf/libs/core/leap/tests/sysf_ipc_test.cc
--- a/osaf/libs/core/leap/tests/sysf_ipc_test.cc
+++ b/osaf/libs/core/leap/tests/sysf_ipc_test.cc
@@ -38,11 +38,10 @@ typedef struct message_ {
bool mbox_clean(NCSCONTEXT arg, NCSCONTEXT msg) {
Message *curr;
- Message *temp;
/* clean the entire mailbox */
for (curr = (Message *)msg; curr;) {
- temp = curr;
+ Message* temp = curr;
curr = curr->next;
delete temp;
@@ -68,20 +67,22 @@ class SysfIpcTest : public ::testing::Te
// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following methods:
+ // cppcheck-suppress unusedFunction
virtual void SetUp() {
// Code here will be called immediately after the constructor (right
// before each test).
- int rc = ncs_leap_startup();
+ ncs_leap_startup();
// see ticket #1629, return code should be ok
//ASSERT_EQ(rc, NCSCC_RC_SUCCESS);
- rc = m_NCS_IPC_CREATE(&mbox);
+ int rc = m_NCS_IPC_CREATE(&mbox);
ASSERT_EQ(rc, NCSCC_RC_SUCCESS);
rc = m_NCS_IPC_ATTACH(&mbox);
ASSERT_EQ(rc, NCSCC_RC_SUCCESS);
}
+ // cppcheck-suppress unusedFunction
virtual void TearDown() {
// Code here will be called immediately after each test (right
// before the destructor).
@@ -120,19 +121,16 @@ class SysfIpcTest : public ::testing::Te
//
static void MessageSender() {
- Message *msg;
- int prio;
srand(time(NULL));
- int rc = NCSCC_RC_SUCCESS;
for (int i = 0; i < 60; ++i) {
- msg = new Message;
+ Message* msg = new Message;
- prio = (random() % 3) + 1;
+ int prio = (random() % 3) + 1;
msg->prio = (NCS_IPC_PRIORITY) prio;
msg->seq_no = i;
- rc = m_NCS_IPC_SEND(&mbox, msg, msg->prio);
+ int rc = m_NCS_IPC_SEND(&mbox, msg, msg->prio);
EXPECT_EQ(rc, NCSCC_RC_SUCCESS);
no_of_msgs_sent++;
diff --git a/osaf/libs/core/leap/tests/sysf_tmr_test.cc
b/osaf/libs/core/leap/tests/sysf_tmr_test.cc
--- a/osaf/libs/core/leap/tests/sysf_tmr_test.cc
+++ b/osaf/libs/core/leap/tests/sysf_tmr_test.cc
@@ -15,7 +15,9 @@ class SysfTmrTest : public ::testing::Te
public:
protected:
- SysfTmrTest() : distribution_(1 * 60 * 60 * 100, 2 * 60 * 60 * 100 - 1) {
+ SysfTmrTest() :
+ distribution_(1 * 60 * 60 * 100, 2 * 60 * 60 * 100 - 1),
+ timers_{} {
// Setup work can be done here for each test.
}
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports. http://pubads.g.doubleclick.net/gampad/clk?id=1444514421&iu=/41014381
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel