[AGENT++] For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'

Claus Klein claus.klein at arcormail.de
Sun Aug 19 20:03:34 CEST 2018


Hi,

I would like to increase the code quality. One way to do this is using cppcheck.
Description:          Cppcheck is an analysis tool for C and C++ code.
    
    Unlike compilers and many other analysis tools, we do not detect syntax
    errors. Cppcheck only detects the types of bugs that the compilers
    normally fail to detect.  The goal is no false positives.

Homepage:             http://cppcheck.sourceforge.net/

With this simple makefile:
.PHONY: all cppcheck
all: cppcheck
cppcheck:
	cppcheck -j 2 --template=gcc --force --std=c++03 --std=posix --platform=unix32 --enable=all . \
		 2>&1 | tee cppcheck-err.txt


It is possible to produce this output:

cppcheck: unusedFunction check can't be used with '-j' option. Disabling unusedFunction check.
Checking agenpro/agent/src/agent.cpp ...
Checking agenpro/simagent/src/agent.cpp ...
agenpro/agent/src/agent.cpp:351:0: warning: The scope of the variable 'req' can be reduced. [variableScope]
    Request* req;
^
Checking agenpro/agent/src/agent.cpp: AGENTPP_NAMESPACE...
agenpro/simagent/src/agent.cpp:458:0: warning: The scope of the variable 'req' can be reduced. [variableScope]
    Request* req;
^
agenpro/simagent/src/agent.cpp:223:0: warning: sscanf() without field width limits can crash with huge input data. [invalidscanf]
    CASE_ARG('a', {
^
agenpro/simagent/src/agent.cpp:227:0: warning: sscanf() without field width limits can crash with huge input data. [invalidscanf]
    CASE_ARG('t', {
^
Checking agenpro/agent/src/agent.cpp: _SNMPv3...
Checking agenpro/simagent/src/agent.cpp: AGENTPP_NAMESPACE...
1/44 files checked 0% done
Checking examples/atm_mib/src/agent.cpp ...
examples/atm_mib/src/agent.cpp:489:0: warning: The scope of the variable 'req' can be reduced. [variableScope]
    Request* req;
^
Checking examples/atm_mib/src/agent.cpp: AGENTPP_NAMESPACE...
Checking examples/atm_mib/src/agent.cpp: SNMP_PP_NAMESPACE...
Checking agenpro/simagent/src/agent.cpp: _SNMPv3...
Checking examples/atm_mib/src/agent.cpp: SNMP_PP_WITH_UDPADDR...
Checking examples/atm_mib/src/agent.cpp: _NO_THREADS;_SNMPv3...
Checking examples/atm_mib/src/agent.cpp: _SNMPv3...
2/44 files checked 0% done
Checking examples/atm_mib/src/agentpp_notifytest_mib.cpp ...
3/44 files checked 1% done
Checking examples/atm_mib/src/agentpp_test_mib.cpp ...
Checking examples/atm_mib/src/agentpp_notifytest_mib.cpp: AGENTPP_NAMESPACE...
Checking examples/atm_mib/src/agentpp_test_mib.cpp: AGENTPP_NAMESPACE...
Checking examples/atm_mib/src/agentpp_notifytest_mib.cpp: SNMP_PP_NAMESPACE...
Checking examples/atm_mib/src/agentpp_test_mib.cpp: SNMP_PP_NAMESPACE...
4/44 files checked 2% done
Checking examples/atm_mib/src/atm_mib.cpp ...
Checking examples/atm_mib/src/agentpp_test_mib.cpp: ___never_defined___...
5/44 files checked 2% done
Checking examples/cmd_exe_mib/src/agent.cpp ...
examples/cmd_exe_mib/src/agent.cpp:415:0: warning: The scope of the variable 'req' can be reduced. [variableScope]
    Request* req;
^
Checking examples/cmd_exe_mib/src/agent.cpp: AGENTPP_NAMESPACE...
Checking examples/cmd_exe_mib/src/agent.cpp: SNMP_PP_NAMESPACE...
Checking examples/cmd_exe_mib/src/agent.cpp: SNMP_PP_WITH_UDPADDR...
Checking examples/cmd_exe_mib/src/agent.cpp: _SNMPv3...
6/44 files checked 3% done
Checking examples/cmd_exe_mib/src/cmd_exe_mib.cpp ...
Checking examples/cmd_exe_mib/src/cmd_exe_mib.cpp: _THREADS...
examples/cmd_exe_mib/src/cmd_exe_mib.cpp:88:0: warning: The scope of the variable 'bytes' can be reduced. [variableScope]
    long size, bytes;
^
7/44 files checked 3% done
Checking examples/dynamic_table/src/agent.cpp ...
examples/dynamic_table/src/agent.cpp:430:0: warning: The scope of the variable 'req' can be reduced. [variableScope]
    Request* req;
^
Checking examples/dynamic_table/src/agent.cpp: AGENTPP_NAMESPACE...
Checking examples/dynamic_table/src/agent.cpp: SNMP_PP_NAMESPACE...
Checking examples/dynamic_table/src/agent.cpp: _SNMPv3...
8/44 files checked 4% done
Checking examples/proxy/src/snmp_proxy.cpp ...
Checking examples/atm_mib/src/atm_mib.cpp: AGENTPP_NAMESPACE...
examples/proxy/src/snmp_proxy.cpp:386:0: warning: The scope of the variable 'req' can be reduced. [variableScope]
    Request* req;
^
Checking examples/proxy/src/snmp_proxy.cpp: AGENTPP_NAMESPACE...
Checking examples/proxy/src/snmp_proxy.cpp: SNMP_PP_NAMESPACE...
Checking examples/proxy/src/snmp_proxy.cpp: _SNMPv3...
9/44 files checked 4% done
Checking examples/proxy_forwarder/src/agent.cpp ...
Checking examples/proxy_forwarder/src/agent.cpp: _SNMPv3;_PROXY_FORWARDER...
examples/proxy_forwarder/src/agent.cpp:407:0: warning: The scope of the variable 'req' can be reduced. [variableScope]
    Request* req;
^
10/44 files checked 5% done
Checking examples/static_table/src/agent.cpp ...
examples/static_table/src/agent.cpp:413:0: warning: The scope of the variable 'req' can be reduced. [variableScope]
    Request* req;
^
Checking examples/static_table/src/agent.cpp: AGENTPP_NAMESPACE...
Checking examples/static_table/src/agent.cpp: SNMP_PP_NAMESPACE...
Checking examples/static_table/src/agent.cpp: _SNMPv3...
11/44 files checked 5% done
Checking src/agentpp_config_mib.cpp ...
Checking src/agentpp_config_mib.cpp: AGENTPP_NAMESPACE;_SNMPv3...
Checking examples/atm_mib/src/atm_mib.cpp: SNMP_PP_NAMESPACE...
Checking src/agentpp_config_mib.cpp: _SNMPv3...
Checking src/agentpp_config_mib.cpp: ___NEVER_DEFINE_THIS___...
12/44 files checked 8% done
Checking src/agentpp_simulation_mib.cpp ...
Checking src/agentpp_simulation_mib.cpp: AGENTPP_NAMESPACE...
Checking src/agentpp_simulation_mib.cpp: _SNMPv3...
13/44 files checked 11% done
Checking src/avl_map.cpp ...
Checking src/avl_map.cpp: AGENTPP_NAMESPACE...
14/44 files checked 12% done
Checking src/map.cpp ...
Checking src/map.cpp: AGENTPP_NAMESPACE...
15/44 files checked 15% done
Checking src/mib.cpp ...
16/44 files checked 18% done
Checking src/mib_avl_map.cpp ...
Checking src/mib_avl_map.cpp: AGENTPP_NAMESPACE...
src/mib.cpp:1024:0: warning: The scope of the variable 'r' can be reduced. [variableScope]
    MibTableRow* r;
^
src/mib.cpp:2256:0: warning: The scope of the variable 'o' can be reduced. [variableScope]
    MibLeaf* o;
^
17/44 files checked 21% done
Checking src/mib_complex_entry.cpp ...
Checking src/mib_complex_entry.cpp: AGENTPP_NAMESPACE...
18/44 files checked 24% done
Checking src/mib_context.cpp ...
Checking src/mib_context.cpp: AGENTPP_NAMESPACE...
19/44 files checked 27% done
Checking src/mib_entry.cpp ...
src/mib_entry.cpp:185:0: warning: The scope of the variable 'buf' can be reduced. [variableScope]
    char* buf;
^
src/mib_entry.cpp:186:0: warning: The scope of the variable 'bytes' can be reduced. [variableScope]
    int size, bytes;
^
src/mib_entry.cpp:208:0: warning: The scope of the variable 'f' can be reduced. [variableScope]
    FILE* f;
^
Checking src/mib_entry.cpp: AGENTPP_NAMESPACE...
20/44 files checked 30% done
Checking src/mib_map.cpp ...
Checking src/mib_map.cpp: AGENTPP_NAMESPACE...
Checking src/mib_map.cpp: __GNUG__...
21/44 files checked 33% done
Checking src/mib_policy.cpp ...
Checking src/mib_policy.cpp: AGENTPP_NAMESPACE...
22/44 files checked 36% done
Checking src/mib_proxy.cpp ...
src/mib_proxy.cpp:125:0: warning: The scope of the variable 'status' can be reduced. [variableScope]
    int status, errind;
^
src/mib_proxy.cpp:125:0: warning: The scope of the variable 'errind' can be reduced. [variableScope]
    int status, errind;
^
src/mib_proxy.cpp:173:0: warning: The scope of the variable 'status' can be reduced. [variableScope]
    int status, errind;
^
src/mib_proxy.cpp:173:0: warning: The scope of the variable 'errind' can be reduced. [variableScope]
    int status, errind;
^
Checking src/mib_proxy.cpp: AGENTPP_NAMESPACE...
Checking src/mib_proxy.cpp: _SNMPv3...
src/mib_proxy.cpp:464:0: warning: The scope of the variable 'status' can be reduced. [variableScope]
    int status;
^
src/mib_proxy.cpp:509:0: warning: The scope of the variable 'status' can be reduced. [variableScope]
    int status;
^
Checking src/mib.cpp: AGENTPP_NAMESPACE...
23/44 files checked 39% done
Checking src/notification_log_mib.cpp ...
Checking src/notification_log_mib.cpp: AGENTPP_NAMESPACE;_SNMPv3...
Checking src/notification_log_mib.cpp: _SNMPv3...
24/44 files checked 42% done
Checking src/notification_originator.cpp ...
Checking src/notification_originator.cpp: AGENTPP_NAMESPACE...
Checking src/notification_originator.cpp: _SNMPv3...
25/44 files checked 45% done
Checking src/proxy_forwarder.cpp ...
Checking src/proxy_forwarder.cpp: AGENTPP_NAMESPACE;_PROXY_FORWARDER;_SNMPv3...
Checking src/proxy_forwarder.cpp: _PROXY_FORWARDER;_SNMPv3...
Checking src/mib.cpp: AGENTPP_USE_THREAD_POOL...
Checking src/proxy_forwarder.cpp: _SNMPv3...
26/44 files checked 48% done
Checking src/request.cpp ...
src/request.cpp:720:0: warning: The scope of the variable 'j' can be reduced. [variableScope]
    int j      = 0;
^
Checking src/request.cpp: AGENTPP_NAMESPACE...
Checking src/request.cpp: NO_FAST_MUTEXES...
Checking src/request.cpp: SNMPv3...
Checking src/mib.cpp: AGENTPP_USE_THREAD_POOL;_THREADS...
Checking src/request.cpp: _PROXY_FORWARDER;_SNMPv3...
Checking src/request.cpp: _SNMPv3...
Checking src/request.cpp: _THREADS...
27/44 files checked 51% done
Checking src/sim_mib.cpp ...
Checking src/sim_mib.cpp: AGENTPP_NAMESPACE...
28/44 files checked 54% done
Checking src/snmp_community_mib.cpp ...
Checking src/snmp_community_mib.cpp: AGENTPP_NAMESPACE;_SNMPv3...
Checking src/mib.cpp: STATIC_REQUEST_LIST...
Checking src/snmp_community_mib.cpp: _SNMPv3...
29/44 files checked 57% done
Checking src/snmp_counters.cpp ...
Checking src/snmp_counters.cpp: AGENTPP_NAMESPACE...
30/44 files checked 60% done
Checking src/snmp_group.cpp ...
Checking src/snmp_group.cpp: AGENTPP_NAMESPACE...
31/44 files checked 63% done
Checking src/snmp_notification_mib.cpp ...
Checking src/snmp_notification_mib.cpp: AGENTPP_NAMESPACE...
32/44 files checked 66% done
Checking src/snmp_pp_ext.cpp ...
src/snmp_pp_ext.cpp:847:0: warning: The scope of the variable 'nfound' can be reduced. [variableScope]
    int nfound = 0;
^
Checking src/snmp_pp_ext.cpp: AGENTPP_NAMESPACE...
Checking src/snmp_pp_ext.cpp: HAVE_POLL_SYSCALL...
Checking src/snmp_pp_ext.cpp: HAVE_POLL_SYSCALL;SNMP_PP_IPv6...
Checking src/mib.cpp: USE_ARRAY_TEMPLATE...
Checking src/snmp_pp_ext.cpp: HAVE_POLL_SYSCALL;SNMP_PP_IPv6;_SNMPv3...
src/snmp_pp_ext.cpp:590:0: warning: The scope of the variable 'nfound' can be reduced. [variableScope]
    int nfound            = 0;
^
Checking src/snmp_pp_ext.cpp: HAVE_POLL_SYSCALL;_SNMPv3...
Checking src/snmp_pp_ext.cpp: SNMP_PP_IPv6...
Checking src/snmp_pp_ext.cpp: SNMP_PP_IPv6;_SNMPv3...
Checking src/snmp_pp_ext.cpp: SNMP_PP_NAMESPACE...
Checking src/mib.cpp: _AIX...
Checking src/snmp_pp_ext.cpp: SNMP_PP_V3...
Checking src/snmp_pp_ext.cpp: _SNMPv3...
Checking src/mib.cpp: _PROXY_FORWARDER;_SNMPv3...
Checking src/snmp_pp_ext.cpp: _SNMPv3;_THREADS...
Checking src/snmp_pp_ext.cpp: _THREADS...
src/mib.cpp:3309:0: warning: Redundant condition: proxy. '!proxy || (proxy && !proxy->process_request(req))' is equivalent to '!proxy || !proxy->process_request(req)' [redundantCondition]
    if ((!proxy) || ((proxy) && (!proxy->process_request(req)))) {
^
33/44 files checked 69% done
Checking src/snmp_proxy_mib.cpp ...
Checking src/snmp_proxy_mib.cpp: AGENTPP_NAMESPACE...
34/44 files checked 72% done
Checking src/snmp_request.cpp ...
src/snmp_request.cpp:302:0: warning: The scope of the variable 'osz' can be reduced. [variableScope]
    int osz    = 0;
^
Checking src/snmp_request.cpp: AGENTPP_NAMESPACE...
Checking src/snmp_request.cpp: USE_LISTEN_ADDRESS_FOR_SENDING_TRAPS...
Checking src/snmp_request.cpp: _SNMPv3...
Checking src/snmp_request.cpp: _THREADS...
Checking src/snmp_request.cpp: _THREADS;_WIN32THREADS...
35/44 files checked 75% done
Checking src/snmp_target_mib.cpp ...
src/snmp_target_mib.cpp:446:0: warning: Redundant condition: status. '!status || (status && status->get()==rowActive)' is equivalent to '!status || status->get()==rowActive' [redundantCondition]
        if (((!status) || ((status) && (status->get() == rowActive)))
^
Checking src/mib.cpp: _SNMPv3...
Checking src/snmp_target_mib.cpp: AGENTPP_NAMESPACE...
Checking src/snmp_target_mib.cpp: _SNMPv3...
src/snmp_target_mib.cpp:585:0: warning: Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]
        break;
^
36/44 files checked 78% done
Checking src/snmp_textual_conventions.cpp ...
src/snmp_textual_conventions.cpp:716:0: warning: Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'. [localtimeCalled]
    struct tm* dt = localtime(&c);
^
Checking src/snmp_textual_conventions.cpp: AGENTPP_NAMESPACE...
Checking src/snmp_textual_conventions.cpp: __APPLE__;__FreeBSD__...
Checking src/snmp_textual_conventions.cpp: __CYGWIN__...
37/44 files checked 81% done
Checking src/system_group.cpp ...
Checking src/system_group.cpp: AGENTPP_NAMESPACE...
Checking src/system_group.cpp: HAVE_CLOCK_GETTIME...
Checking src/system_group.cpp: WIN32...
Checking src/system_group.cpp: WIN32;__BCPLUSPLUS__...
Checking src/system_group.cpp: _WIN32...
38/44 files checked 84% done
Checking src/mib.cpp: _THREADS...
Checking src/threads.cpp ...
Checking src/threads.cpp: AGENTPP_NAMESPACE...
Checking src/threads.cpp: AGENTPP_PTHREAD_RECURSIVE;POSIX_THREADS;_THREADS...
Checking src/threads.cpp: AGENTPP_QUEUED_THREAD_POOL_USE_ASSIGN;AGENTPP_USE_THREAD_POOL;_THREADS...
src/threads.cpp:550:0: warning: Variable 'wasLocked' is assigned a value that is never used. [unreadVariable]
    bool wasLocked = isLocked;
^
Checking src/threads.cpp: AGENTPP_USE_THREAD_POOL;NO_FAST_MUTEXES;_THREADS...
Checking src/threads.cpp: AGENTPP_USE_THREAD_POOL;_THREADS...
Checking src/threads.cpp: HAVE_CLOCK_GETTIME;POSIX_THREADS;_THREADS...
Checking src/threads.cpp: HAVE_CLOCK_GETTIME;_POSIX_TIMERS;_THREADS...
Checking src/threads.cpp: NO_FAST_MUTEXES;POSIX_THREADS;_THREADS...
Checking src/threads.cpp: NO_FAST_MUTEXES;_THREADS...
Checking src/threads.cpp: POSIX_THREADS;_THREADS...
Checking src/threads.cpp: WIN32;_THREADS...
Checking src/threads.cpp: _POSIX_TIMERS;_THREADS...
Checking src/threads.cpp: _THREADS...
39/44 files checked 87% done
Checking src/tools.cpp ...
Checking src/tools.cpp: AGENTPP_NAMESPACE...
40/44 files checked 90% done
Checking src/v3_mib.cpp ...
Checking src/v3_mib.cpp: AGENTPP_NAMESPACE;_SNMPv3...
Checking src/mib.cpp: _THREADS;_WIN32THREADS...
src/v3_mib.cpp:358:0: warning: The scope of the variable 'user' can be reduced. [variableScope]
    const struct UsmUserTableEntry* user;
^
Checking src/v3_mib.cpp: _NO_LOGGING;_SNMPv3...
Checking src/v3_mib.cpp: _SNMPv3...
Checking src/mib.cpp: _USE_PROXY...
41/44 files checked 93% done
Checking src/vacm.cpp ...
Checking src/vacm.cpp: AGENTPP_NAMESPACE...
42/44 files checked 96% done
Checking tools/agent_copy/src/agent_copy.cpp ...
Checking tools/agent_copy/src/agent_copy.cpp: AGENTPP_NAMESPACE...
Checking tools/agent_copy/src/agent_copy.cpp: SNMP_PP_NAMESPACE...
Checking src/vacm.cpp: _SNMPv3...
Checking tools/agent_copy/src/agent_copy.cpp: _SNMPv3...
43/44 files checked 96% done
44/44 files checked 100% done



More information about the AGENTPP mailing list