Menu

#1879 base: Fix cppcheck warnings

5.1.FC
fixed
None
enhancement
base
-
5.1.M0
minor
2018-02-07
2016-06-14
No

cppcheck version 1.74 reports the following warnings in the BASE component:

Line Id CWE Severity Message
osaf/libs/core/common/daemon.c
212 variableScope 398 style The scope of the variable 'plibc_prctl' can be reduced.
214 variableScope 398 style The scope of the variable 'pid' can be reduced.
214 variableScope 398 style The scope of the variable 'sid' can be reduced.
256 uninitvar 908 error Uninitialized variable: param
340 getpwnamCalled portability Non reentrant function 'getpwnam' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwnam_r'.
505 variableScope 398 style The scope of the variable 'bt_filename_size' can be reduced.
507 variableScope 398 style The scope of the variable 'time_string' can be reduced.
510 variableScope 398 style The scope of the variable 'i' can be reduced.
528 uninitvar 908 error Uninitialized variable: time_string
533 localtimeCalled portability Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'.
539 uninitvar 908 error Uninitialized variable: time_string
osaf/libs/core/common/ncs_main_pub.c
129 unusedStructMember style struct member 'ncs_main_pub_cb::lock_create' is never used.
178 redundantAssignment 563 style Variable 'rc' is reassigned a value before the old one has been used.
315 redundantAssignment 563 style Variable 'rc' is reassigned a value before the old one has been used.
693 unreadVariable style Variable 'res' is assigned a value that is never used.
714 variableScope 398 style The scope of the variable 'p_field' can be reduced.
794 variableScope 398 style The scope of the variable 'tmp' can be reduced.
osaf/libs/core/common/nid_start_util.c
54 invalidscanf warning fscanf() without field width limits can crash with huge input data.
osaf/libs/core/common/osaf_extended_name.c
183 uninitdata 908 error Memory is allocated but not initialized: pointer
osaf/libs/core/common/osaf_poll.c
117 uninitvar 908 error Uninitialized variable: elapsed_time
118 uninitvar 908 error Uninitialized variable: elapsed_time
120 uninitvar 908 error Uninitialized variable: elapsed_time
134 uninitvar 908 error Uninitialized variable: set
135 uninitvar 908 error Uninitialized variable: set
osaf/libs/core/common/osaf_secutil.c
82 uninitvar 908 error Uninitialized variable: fds
83 uninitvar 908 error Uninitialized variable: fds
136 uninitvar 908 error Uninitialized variable: unaddr
170 uninitvar 908 error Uninitialized variable: fds
171 uninitvar 908 error Uninitialized variable: fds
203 uninitdata 908 error Memory is allocated but not initialized: fd
243 getpwuidCalled portability Non reentrant function 'getpwuid' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwuid_r'.
279 uninitvar 908 error Uninitialized variable: remote
295 uninitvar 908 error Uninitialized variable: fds
296 uninitvar 908 error Uninitialized variable: fds
353 getpwuidCalled portability Non reentrant function 'getpwuid' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwuid_r'.
370 getgrentCalled portability Non reentrant function 'getgrent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getgrent_r'.
379 getgrentCalled portability Non reentrant function 'getgrent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getgrent_r'.
399 getgrentCalled 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_timerfd.c
184 uninitvar 908 error Uninitialized variable: event
185 uninitvar 908 error Uninitialized variable: event
186 uninitvar 908 error Uninitialized variable: event
187 uninitvar 908 error Uninitialized variable: event
osaf/libs/core/cplusplus/base/tests/time_compare_test.cc
25 duplicateExpression 398 style Same expression on both sides of '<'.
26 duplicateExpression 398 style Same expression on both sides of '<='.
29 duplicateExpression 398 style Same expression on both sides of '>='.
30 duplicateExpression 398 style Same expression on both sides of '>'.
70 duplicateExpression 398 style Same expression on both sides of '<'.
71 duplicateExpression 398 style Same expression on both sides of '<='.
74 duplicateExpression 398 style Same expression on both sides of '>='.
75 duplicateExpression 398 style Same expression on both sides of '>'.
97 duplicateExpression 398 style Same expression on both sides of '<'.
98 duplicateExpression 398 style Same expression on both sides of '<='.
101 duplicateExpression 398 style Same expression on both sides of '>='.
102 duplicateExpression 398 style Same expression on both sides of '>'.
osaf/libs/core/leap/hj_edp.c
169 variableScope 398 style The scope of the variable 'len' can be reduced.
352 variableScope 398 style The scope of the variable 'len' can be reduced.
352 variableScope 398 style The scope of the variable 'byte_cnt' can be reduced.
778 variableScope 398 style The scope of the variable 'byte_cnt' can be reduced.
1661 sizeofDivisionMemfunc warning Division by result of sizeof(). malloc() expects a size in bytes, did you intend to multiply instead?
1813 sizeofDivisionMemfunc 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 variableScope 398 style The scope of the variable 'arguments' can be reduced.
284 variableScope 398 style The scope of the variable 'arguments' can be reduced.
413 variableScope 398 style The scope of the variable 'dtype_attrb' can be reduced.
415 variableScope 398 style The scope of the variable 'cnt' can be reduced.
445 uninitvar 908 error Uninitialized variable: admin_op
446 uninitvar 908 error Uninitialized variable: admin_op
498 unreadVariable style Variable 'admin_op' is assigned a value that is never used.
2478 variableScope 398 style The scope of the variable 'lclfnd' can be reduced.
2528 variableScope 398 style The scope of the variable 'already_added' can be reduced.
3244 variableScope 398 style The scope of the variable 'new_node' can be reduced.
3296 uninitvar 908 error Uninitialized variable: list_params
3321 variableScope 398 style The scope of the variable 'key' can be reduced.
3322 variableScope 398 style The scope of the variable 'pnode' can be reduced.
3328 unreadVariable style Variable 'lcl_key' is assigned a value that is never used.
3447 variableScope 398 style The scope of the variable 'val' can be reduced.
3499 variableScope 398 style The scope of the variable 'val' can be reduced.
3529 variableScope 398 style The scope of the variable 'i' can be reduced.
3626 variableScope 398 style The scope of the variable 'val' can be reduced.
3679 variableScope 398 style The scope of the variable 'val' can be reduced.
osaf/libs/core/leap/hj_enc.c
58 variableScope 398 style The scope of the variable 'p' can be reduced.
osaf/libs/core/leap/hj_hdl.c
193 uninitvar 908 error Uninitialized variable: ha
194 uninitvar 908 error Uninitialized variable: ha
195 uninitvar 908 error Uninitialized variable: ha
196 uninitvar 908 error Uninitialized variable: ha
231 variableScope 398 style The scope of the variable 'unit' can be reduced.
271 variableScope 398 style The scope of the variable 'cell' can be reduced.
311 variableScope 398 style The scope of the variable 'cell' can be reduced.
547 variableScope 398 style The scope of the variable 'cell' can be reduced.
578 uninitvar 908 error Uninitialized variable: hdl
579 uninitvar 908 error Uninitialized variable: hdl
580 uninitvar 908 error Uninitialized variable: hdl
613 variableScope 398 style The scope of the variable 'cell' can be reduced.
617 variableScope 398 style The scope of the variable 'i' can be reduced.
osaf/libs/core/leap/hj_tmr.c
389 variableScope 398 style The scope of the variable 'tmr_info' can be reduced.
425 variableScope 398 style The scope of the variable 'pres_tmr_info' can be reduced.
471 variableScope 398 style The scope of the variable 'prev_tmr_info' can be reduced.
osaf/libs/core/leap/hj_ubaid.c
708 variableScope 398 style The scope of the variable 'p' can be reduced.
osaf/libs/core/leap/os_defs.c
505 variableScope 398 style The scope of the variable 'tmp_hdl' can be reduced.
593 uninitvar 908 error Uninitialized variable: os_req
595 uninitvar 908 error Uninitialized variable: os_req
597 uninitvar 908 error Uninitialized variable: os_req
598 uninitvar 908 error Uninitialized variable: os_req
599 uninitvar 908 error Uninitialized variable: os_req
600 uninitvar 908 error Uninitialized variable: os_req
614 uninitvar 908 error Uninitialized variable: os_req
616 uninitvar 908 error Uninitialized variable: os_req
618 uninitvar 908 error Uninitialized variable: os_req
619 uninitvar 908 error Uninitialized variable: os_req
620 uninitvar 908 error Uninitialized variable: os_req
621 uninitvar 908 error Uninitialized variable: os_req
645 variableScope 398 style The scope of the variable 'file' can be reduced.
654 uninitvar 908 error Uninitialized variable: os_req
661 uninitvar 908 error Uninitialized variable: os_req
667 uninitvar 908 error Uninitialized variable: os_req
670 uninitvar 908 error Uninitialized variable: os_req
694 uninitvar 908 error Uninitialized variable: os_req
695 uninitvar 908 error Uninitialized variable: os_req
696 uninitvar 908 error Uninitialized variable: os_req
706 uninitvar 908 error Uninitialized variable: os_req
707 uninitvar 908 error Uninitialized variable: os_req
773 variableScope 398 style The scope of the variable 'prot_flag' can be reduced.
osaf/libs/core/leap/sysf_exc_scr.c
109 uninitvar 908 error Uninitialized variable: info
110 uninitvar 908 error Uninitialized variable: info
111 uninitvar 908 error Uninitialized variable: info
146 uninitvar 908 error Uninitialized variable: info
147 uninitvar 908 error Uninitialized variable: info
148 uninitvar 908 error Uninitialized variable: info
404 uninitvar 908 error Uninitialized variable: pt_params
460 variableScope 398 style The scope of the variable 'exec_pid' can be reduced.
osaf/libs/core/leap/sysf_ipc.c
454 variableScope 398 style The scope of the variable 'inds_rmvd' can be reduced.
osaf/libs/core/leap/sysf_mem.c
747 uninitvar 908 error Uninitialized variable: l_util
854 variableScope 398 style The scope of the variable 'pub' can be reduced.
856 variableScope 398 style The scope of the variable 'buflen' can be reduced.
944 variableScope 398 style The scope of the variable 'buflen' can be reduced.
1162 variableScope 398 style The scope of the variable 'i' can be reduced.
1170 variableScope 398 style The scope of the variable 'dest' can be reduced.
1478 variableScope 398 style The scope of the variable 'bufsize' can be reduced.
1735 variableScope 398 style The scope of the variable 'len' can be reduced.
1736 variableScope 398 style The scope of the variable 'dst' can be reduced.
1917 variableScope 398 style The scope of the variable 'file' can be reduced.
osaf/libs/core/leap/sysf_tmr.c
166 unusedStructMember style struct member 'sysf_tmr_cb::stats' is never used.
390 variableScope 398 style The scope of the variable 'rc' can be reduced.
545 variableScope 398 style The scope of the variable 'free_tmr' can be reduced.
osaf/libs/core/leap/sysf_tsk.c
53 uninitvar 908 error Uninitialized variable: task
54 uninitvar 908 error Uninitialized variable: task
55 uninitvar 908 error Uninitialized variable: task
56 uninitvar 908 error Uninitialized variable: task
57 uninitvar 908 error Uninitialized variable: task
58 uninitvar 908 error Uninitialized variable: task
75 uninitvar 908 error Uninitialized variable: task
87 uninitvar 908 error Uninitialized variable: task
99 uninitvar 908 error Uninitialized variable: task
111 uninitvar 908 error Uninitialized variable: task
123 uninitvar 908 error Uninitialized variable: task
132 uninitvar 908 error Uninitialized variable: task
osaf/libs/core/leap/tests/sysf_ipc_test.cc
41 variableScope 398 style The scope of the variable 'temp' can be reduced.
74 redundantAssignment 563 style Variable 'rc' is reassigned a value before the old one has been used.
123 variableScope 398 style The scope of the variable 'msg' can be reduced.
124 variableScope 398 style The scope of the variable 'prio' can be reduced.
126 variableScope 398 style The scope of the variable 'rc' can be reduced.
osaf/libs/core/leap/tests/sysf_tmr_test.cc
18 uninitMemberVar 398 warning Member variable 'SysfTmrTest::timers_' is not initialized in the constructor.

Related

Tickets: #1879

Discussion

  • Anders Widell

    Anders Widell - 2016-06-14
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -2,7 +2,7 @@
    
     Line | Id | CWE | Severity | Message
     ---------- | ---------- | ------ | ------ | ------
    -osaf/libs/core/common/daemon.c
    + | | | | osaf/libs/core/common/daemon.c
     212 | variableScope | 398 | style | The scope of the variable 'plibc_prctl' can be reduced.
     214 | variableScope | 398 | style | The scope of the variable 'pid' can be reduced.
     214 | variableScope | 398 | style | The scope of the variable 'sid' can be reduced.
    @@ -14,24 +14,24 @@
     528 | uninitvar | 908 | error | Uninitialized variable: time_string
     533 | localtimeCalled |  | portability | Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'.
     539 | uninitvar | 908 | error | Uninitialized variable: time_string
    -osaf/libs/core/common/ncs_main_pub.c
    + | | | | osaf/libs/core/common/ncs_main_pub.c
     129 | unusedStructMember |  | style | struct member 'ncs_main_pub_cb::lock_create' is never used.
     178 | redundantAssignment | 563 | style | Variable 'rc' is reassigned a value before the old one has been used.
     315 | redundantAssignment | 563 | style | Variable 'rc' is reassigned a value before the old one has been used.
     693 | unreadVariable |  | style | Variable 'res' is assigned a value that is never used.
     714 | variableScope | 398 | style | The scope of the variable 'p_field' can be reduced.
     794 | variableScope | 398 | style | The scope of the variable 'tmp' can be reduced.
    -osaf/libs/core/common/nid_start_util.c
    + | | | | osaf/libs/core/common/nid_start_util.c
     54 | invalidscanf |  | warning | fscanf() without field width limits can crash with huge input data.
    -osaf/libs/core/common/osaf_extended_name.c
    + | | | | osaf/libs/core/common/osaf_extended_name.c
     183 | uninitdata | 908 | error | Memory is allocated but not initialized: pointer
    -osaf/libs/core/common/osaf_poll.c
    + | | | | osaf/libs/core/common/osaf_poll.c
     117 | uninitvar | 908 | error | Uninitialized variable: elapsed_time
     118 | uninitvar | 908 | error | Uninitialized variable: elapsed_time
     120 | uninitvar | 908 | error | Uninitialized variable: elapsed_time
     134 | uninitvar | 908 | error | Uninitialized variable: set
     135 | uninitvar | 908 | error | Uninitialized variable: set
    -osaf/libs/core/common/osaf_secutil.c
    + | | | | osaf/libs/core/common/osaf_secutil.c
     82 | uninitvar | 908 | error | Uninitialized variable: fds
     83 | uninitvar | 908 | error | Uninitialized variable: fds
     136 | uninitvar | 908 | error | Uninitialized variable: unaddr
    @@ -46,12 +46,12 @@
     370 | getgrentCalled |  | portability | Non reentrant function 'getgrent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getgrent_r'.
     379 | getgrentCalled |  | portability | Non reentrant function 'getgrent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getgrent_r'.
     399 | getgrentCalled |  | 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_timerfd.c
    + | | | | osaf/libs/core/common/osaf_timerfd.c
     184 | uninitvar | 908 | error | Uninitialized variable: event
     185 | uninitvar | 908 | error | Uninitialized variable: event
     186 | uninitvar | 908 | error | Uninitialized variable: event
     187 | uninitvar | 908 | error | Uninitialized variable: event
    -osaf/libs/core/cplusplus/base/tests/time_compare_test.cc
    + | | | | osaf/libs/core/cplusplus/base/tests/time_compare_test.cc
     25 | duplicateExpression | 398 | style | Same expression on both sides of '<'.
     26 | duplicateExpression | 398 | style | Same expression on both sides of '<='.
     29 | duplicateExpression | 398 | style | Same expression on both sides of '>='.
    @@ -64,14 +64,14 @@
     98 | duplicateExpression | 398 | style | Same expression on both sides of '<='.
     101 | duplicateExpression | 398 | style | Same expression on both sides of '>='.
     102 | duplicateExpression | 398 | style | Same expression on both sides of '>'.
    -osaf/libs/core/leap/hj_edp.c
    + | | | | osaf/libs/core/leap/hj_edp.c
     169 | variableScope | 398 | style | The scope of the variable 'len' can be reduced.
     352 | variableScope | 398 | style | The scope of the variable 'len' can be reduced.
     352 | variableScope | 398 | style | The scope of the variable 'byte_cnt' can be reduced.
     778 | variableScope | 398 | style | The scope of the variable 'byte_cnt' can be reduced.
     1661 | sizeofDivisionMemfunc |  | warning | Division by result of sizeof(). malloc() expects a size in bytes, did you intend to multiply instead?
     1813 | sizeofDivisionMemfunc |  | 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
    + | | | | osaf/libs/core/leap/hj_edu.c
     132 | variableScope | 398 | style | The scope of the variable 'arguments' can be reduced.
     284 | variableScope | 398 | style | The scope of the variable 'arguments' can be reduced.
     413 | variableScope | 398 | style | The scope of the variable 'dtype_attrb' can be reduced.
    @@ -91,9 +91,9 @@
     3529 | variableScope | 398 | style | The scope of the variable 'i' can be reduced.
     3626 | variableScope | 398 | style | The scope of the variable 'val' can be reduced.
     3679 | variableScope | 398 | style | The scope of the variable 'val' can be reduced.
    -osaf/libs/core/leap/hj_enc.c
    + | | | | osaf/libs/core/leap/hj_enc.c
     58 | variableScope | 398 | style | The scope of the variable 'p' can be reduced.
    -osaf/libs/core/leap/hj_hdl.c
    + | | | | osaf/libs/core/leap/hj_hdl.c
     193 | uninitvar | 908 | error | Uninitialized variable: ha
     194 | uninitvar | 908 | error | Uninitialized variable: ha
     195 | uninitvar | 908 | error | Uninitialized variable: ha
    @@ -107,13 +107,13 @@
     580 | uninitvar | 908 | error | Uninitialized variable: hdl
     613 | variableScope | 398 | style | The scope of the variable 'cell' can be reduced.
     617 | variableScope | 398 | style | The scope of the variable 'i' can be reduced.
    -osaf/libs/core/leap/hj_tmr.c
    + | | | | osaf/libs/core/leap/hj_tmr.c
     389 | variableScope | 398 | style | The scope of the variable 'tmr_info' can be reduced.
     425 | variableScope | 398 | style | The scope of the variable 'pres_tmr_info' can be reduced.
     471 | variableScope | 398 | style | The scope of the variable 'prev_tmr_info' can be reduced.
    -osaf/libs/core/leap/hj_ubaid.c
    + | | | | osaf/libs/core/leap/hj_ubaid.c
     708 | variableScope | 398 | style | The scope of the variable 'p' can be reduced.
    -osaf/libs/core/leap/os_defs.c
    + | | | | osaf/libs/core/leap/os_defs.c
     505 | variableScope | 398 | style | The scope of the variable 'tmp_hdl' can be reduced.
     593 | uninitvar | 908 | error | Uninitialized variable: os_req
     595 | uninitvar | 908 | error | Uninitialized variable: os_req
    @@ -138,7 +138,7 @@
     706 | uninitvar | 908 | error | Uninitialized variable: os_req
     707 | uninitvar | 908 | error | Uninitialized variable: os_req
     773 | variableScope | 398 | style | The scope of the variable 'prot_flag' can be reduced.
    -osaf/libs/core/leap/sysf_exc_scr.c
    + | | | | osaf/libs/core/leap/sysf_exc_scr.c
     109 | uninitvar | 908 | error | Uninitialized variable: info
     110 | uninitvar | 908 | error | Uninitialized variable: info
     111 | uninitvar | 908 | error | Uninitialized variable: info
    @@ -147,9 +147,9 @@
     148 | uninitvar | 908 | error | Uninitialized variable: info
     404 | uninitvar | 908 | error | Uninitialized variable: pt_params
     460 | variableScope | 398 | style | The scope of the variable 'exec_pid' can be reduced.
    -osaf/libs/core/leap/sysf_ipc.c
    + | | | | osaf/libs/core/leap/sysf_ipc.c
     454 | variableScope | 398 | style | The scope of the variable 'inds_rmvd' can be reduced.
    -osaf/libs/core/leap/sysf_mem.c
    + | | | | osaf/libs/core/leap/sysf_mem.c
     747 | uninitvar | 908 | error | Uninitialized variable: l_util
     854 | variableScope | 398 | style | The scope of the variable 'pub' can be reduced.
     856 | variableScope | 398 | style | The scope of the variable 'buflen' can be reduced.
    @@ -160,11 +160,11 @@
     1735 | variableScope | 398 | style | The scope of the variable 'len' can be reduced.
     1736 | variableScope | 398 | style | The scope of the variable 'dst' can be reduced.
     1917 | variableScope | 398 | style | The scope of the variable 'file' can be reduced.
    -osaf/libs/core/leap/sysf_tmr.c
    + | | | | osaf/libs/core/leap/sysf_tmr.c
     166 | unusedStructMember |  | style | struct member 'sysf_tmr_cb::stats' is never used.
     390 | variableScope | 398 | style | The scope of the variable 'rc' can be reduced.
     545 | variableScope | 398 | style | The scope of the variable 'free_tmr' can be reduced.
    -osaf/libs/core/leap/sysf_tsk.c
    + | | | | osaf/libs/core/leap/sysf_tsk.c
     53 | uninitvar | 908 | error | Uninitialized variable: task
     54 | uninitvar | 908 | error | Uninitialized variable: task
     55 | uninitvar | 908 | error | Uninitialized variable: task
    @@ -177,11 +177,11 @@
     111 | uninitvar | 908 | error | Uninitialized variable: task
     123 | uninitvar | 908 | error | Uninitialized variable: task
     132 | uninitvar | 908 | error | Uninitialized variable: task
    -osaf/libs/core/leap/tests/sysf_ipc_test.cc
    + | | | | osaf/libs/core/leap/tests/sysf_ipc_test.cc
     41 | variableScope | 398 | style | The scope of the variable 'temp' can be reduced.
     74 | redundantAssignment | 563 | style | Variable 'rc' is reassigned a value before the old one has been used.
     123 | variableScope | 398 | style | The scope of the variable 'msg' can be reduced.
     124 | variableScope | 398 | style | The scope of the variable 'prio' can be reduced.
     126 | variableScope | 398 | style | The scope of the variable 'rc' can be reduced.
    -osaf/libs/core/leap/tests/sysf_tmr_test.cc
    + | | | | osaf/libs/core/leap/tests/sysf_tmr_test.cc
     18 | uninitMemberVar | 398 | warning | Member variable 'SysfTmrTest::timers_' is not initialized in the constructor.
    
     
  • Anders Widell

    Anders Widell - 2016-06-15
    • status: accepted --> review
     
  • Anders Widell

    Anders Widell - 2016-06-21
    • status: review --> fixed
     
  • Khem Raj

    Khem Raj - 2018-02-07

    I see that getgrent was replaced with getgrent_r which certainly shuts the tool warning but might not be ideal solution. e.g.

    1. getgrent_r is glibc specific function . ( e.g. musl does not have it) so not portable
    2. implementing using getgrouplist() would have been better
    3. Does not work with backends which dont use /etc/group e.g. LDAP

    maybe getgrouplist() should be checked for during configure and preferred if available and then
    fall back to current implementation as a last resort.

     

Log in to post a comment.