From 0257baf1325fffdd80996f980c6f8c537aaf33c0 Mon Sep 17 00:00:00 2001 From: Takeshi Nakatani Date: Mon, 11 Mar 2024 09:00:08 +0900 Subject: [PATCH] Changed support OS and Fixed about cppcheck, etc --- .github/workflows/ci.yml | 25 +++++++++------ .github/workflows/ostypevars.sh | 24 +++++++++++--- Makefile.am | 46 ++++++++++++++++++++------ buildutils/chmpx.spec.in | 8 ++--- buildutils/control.in | 6 ++-- configure.ac | 4 +-- lib/chmcntrl.cc | 8 +++-- lib/chmconf.cc | 32 ++++++++++-------- lib/chmdbg.h | 38 +++++++++++++--------- lib/chmeventmq.cc | 15 +++++---- lib/chmeventsock.cc | 33 ++++++++++++------- lib/chmimdata.cc | 4 +++ lib/chmkvp.cc | 8 ++--- lib/chmkvp.h | 2 +- lib/chmlockmap.tcc | 8 +++++ lib/chmnetdb.cc | 4 +++ lib/chmopts.cc | 4 +-- lib/chmopts.h | 4 +-- lib/chmpx.cc | 6 ++-- lib/chmregex.cc | 4 +++ lib/chmssgnutls.h | 2 ++ lib/chmssnss.h | 2 ++ lib/chmssopenssl.cc | 1 + lib/chmssopenssl.h | 2 ++ lib/chmstream.h | 16 ++++----- lib/chmstructure.tcc | 4 +-- lib/chmthread.cc | 6 ++++ lib/chmutil.cc | 4 +-- lib/chmutil.h | 4 +-- src/chmmain.cc | 2 +- tests/chmpxbench.cc | 22 +++++++++++-- tests/chmpxconftest.cc | 6 ++-- tests/chmpxlinetool.cc | 57 +++++++++++++++++++++++++++------ tests/chmpxstatus.cc | 2 +- tests/chmpxstreamtest.cc | 6 ++-- 35 files changed, 291 insertions(+), 128 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d41586..5acd655 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,19 +69,26 @@ jobs: - rockylinux:9 - rockylinux:8 - centos:centos7 + - fedora:39 - fedora:38 - - fedora:37 + - alpine:3.19 - alpine:3.18 container: image: ${{ matrix.container }} steps: + # [NOTE] + # actions/checkout@v3 uses nodejs v16 and will be deprecated. + # However, @v4 does not work on centos7 depending on the glibc version, + # so we will continue to use @v3. # - # Checks-out your repository under $GITHUB_WORKSPACE, so your - # job can access it - # - - name: Checkout sources + - name: Checkout source code(other than centos7) + if: matrix.container != 'centos:centos7' + uses: actions/checkout@v4 + + - name: Checkout source code(only centos7) + if: matrix.container == 'centos:centos7' uses: actions/checkout@v3 # @@ -153,7 +160,7 @@ jobs: # : If you want to use the created Docker image as the default image, specify "default". # imageinfo: - - alpine:3.18,alpine:3.18,alpine,default + - alpine:3.19,alpine:3.19,alpine,default - ubuntu:22.04,ubuntu:22.04,ubuntu # @@ -161,10 +168,10 @@ jobs: # steps: - name: Checkout sources - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 # # Login to avoid the Docker Hub rate limit @@ -178,7 +185,7 @@ jobs: # - name: Login to DockerHub if: ${{ github.event_name != 'pull_request' }} - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_ACCESSTOKEN }} diff --git a/.github/workflows/ostypevars.sh b/.github/workflows/ostypevars.sh index 141f637..9b93d2c 100644 --- a/.github/workflows/ostypevars.sh +++ b/.github/workflows/ostypevars.sh @@ -228,9 +228,9 @@ elif [ "${CI_OSTYPE}" = "centos:7" ] || [ "${CI_OSTYPE}" = "centos:centos7" ]; t PKG_EXT="rpm" IS_OS_CENTOS=1 -elif [ "${CI_OSTYPE}" = "fedora:38" ]; then - DIST_TAG="fedora/38" - INSTALL_PKG_LIST="git autoconf automake gcc gcc-c++ gdb make libtool pkgconfig redhat-rpm-config rpm-build ruby-devel rubygems procps libyaml-devel k2hash-devel nss-devel" +elif [ "${CI_OSTYPE}" = "fedora:39" ]; then + DIST_TAG="fedora/39" + INSTALL_PKG_LIST="git autoconf automake gcc gcc-c++ gdb make libtool pkgconfig redhat-rpm-config rpm-build ruby-devel rubygems procps libyaml-devel k2hash-devel nss-devel systemd" INSTALLER_BIN="dnf" UPDATE_CMD="update" UPDATE_CMD_ARG="" @@ -242,8 +242,8 @@ elif [ "${CI_OSTYPE}" = "fedora:38" ]; then PKG_EXT="rpm" IS_OS_FEDORA=1 -elif [ "${CI_OSTYPE}" = "fedora:37" ]; then - DIST_TAG="fedora/37" +elif [ "${CI_OSTYPE}" = "fedora:38" ]; then + DIST_TAG="fedora/38" INSTALL_PKG_LIST="git autoconf automake gcc gcc-c++ gdb make libtool pkgconfig redhat-rpm-config rpm-build ruby-devel rubygems procps libyaml-devel k2hash-devel nss-devel" INSTALLER_BIN="dnf" UPDATE_CMD="update" @@ -256,6 +256,20 @@ elif [ "${CI_OSTYPE}" = "fedora:37" ]; then PKG_EXT="rpm" IS_OS_FEDORA=1 +elif [ "${CI_OSTYPE}" = "alpine:3.19" ]; then + DIST_TAG="alpine/v3.19" + INSTALL_PKG_LIST="bash sudo alpine-sdk automake autoconf libtool groff util-linux-misc musl-locales ruby-dev procps yaml-dev k2hash-dev openssl-dev" + INSTALLER_BIN="apk" + UPDATE_CMD="update" + UPDATE_CMD_ARG="--no-progress" + INSTALL_CMD="add" + INSTALL_CMD_ARG="--no-progress --no-cache" + INSTALL_AUTO_ARG="" + INSTALL_QUIET_ARG="-q" + PKG_OUTPUT_DIR="apk_build" + PKG_EXT="apk" + IS_OS_ALPINE=1 + elif [ "${CI_OSTYPE}" = "alpine:3.18" ]; then DIST_TAG="alpine/v3.18" INSTALL_PKG_LIST="bash sudo alpine-sdk automake autoconf libtool groff util-linux-misc musl-locales ruby-dev procps yaml-dev k2hash-dev openssl-dev" diff --git a/Makefile.am b/Makefile.am index 93b94b6..3b3a78c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -33,23 +33,42 @@ EXTRA_DIST=RELEASE_VERSION @CONFIGURECUSTOM@ # Versions of cppcheck below 1.8 perform poorly and the test is # skipped if those versions are installed. # -CPPCHECK_NG_VERSION = -e \^0\\. -e \^1\\.[0-7] +# Since knownConditionTrueFalse and badBitmaskCheck are output a +# lot in debugging macros, so we will exclude it. +# +CPPCHECK_NG_VER = -e \^0\\. -e \^1\\.[0-7] CPPCHECK_CMD = cppcheck CPPCHECK_TARGET = $(SUBDIRS) CPPCHECK_BUILD_DIR = /tmp/cppcheck CPPCHECK_BASE_OPT = --quiet \ --error-exitcode=1 \ --inline-suppr \ - -j 4 \ + -j 8 \ --std=c++03 \ --xml CPPCHECK_ENABLE_OPT = --enable=warning,style,information,missingInclude CPPCHECK_IGNORE_OPT = --suppress=unmatchedSuppression +CPPCHECK_INCDIR_OPT = -I . -I lib CPPCHECK_DEFINE_OPT = -D SO_REUSEPORT +# [NOTE] Switch options +# The options available vary depending on the version. +# There are cases where you use options that do not exist in older +# versions. +# +CPPCHECK_GT204_VER = 2004 +CPPCHECK_GT204_ADD_OPT = --suppress=knownConditionTrueFalse +CPPCHECK_GE207_VER = 2007 +CPPCHECK_GE207_ADD_OPT = --suppress=ctuOneDefinitionRuleViolation +CPPCHECK_GE211_VER = 2011 +CPPCHECK_GE211_ADD_OPT = --check-level=exhaustive \ + --suppress=missingIncludeSystem \ + --suppress=badBitmaskCheck + cppcheck: - @if command -v $(CPPCHECK_CMD) >/dev/null 2>&1; then \ - if ($(CPPCHECK_CMD) --version | sed -e 's|Cppcheck[[:space:]]*||gi' | grep -q $(CPPCHECK_NG_VERSION)); then \ + @set -e; \ + if command -v $(CPPCHECK_CMD) >/dev/null 2>&1; then \ + if ($(CPPCHECK_CMD) --version | sed -e 's|Cppcheck[[:space:]]*||gi' | grep -q $(CPPCHECK_NG_VER)); then \ echo "*** [INFO] cppcheck version below 1.8, so skip to run cppcheck."; \ else \ echo "*** Check all files with CppCheck"; \ @@ -57,7 +76,15 @@ cppcheck: rm -rf $(CPPCHECK_BUILD_DIR); \ fi; \ mkdir -p $(CPPCHECK_BUILD_DIR); \ - $(CPPCHECK_CMD) $(CPPCHECK_BASE_OPT) $(CPPCHECK_DEFINE_OPT) $(CPPCHECK_ENABLE_OPT) $(CPPCHECK_IGNORE_OPT) --cppcheck-build-dir=$(CPPCHECK_BUILD_DIR) $(CPPCHECK_TARGET); \ + if test `$(CPPCHECK_CMD) --version | sed -e 's/\./ /g' | awk '{print ($$2 * 1000 + $$3)}'` -le $(CPPCHECK_GT204_VER); then \ + $(CPPCHECK_CMD) $(CPPCHECK_BASE_OPT) $(CPPCHECK_DEFINE_OPT) $(CPPCHECK_INCDIR_OPT) $(CPPCHECK_ENABLE_OPT) $(CPPCHECK_IGNORE_OPT) --cppcheck-build-dir=$(CPPCHECK_BUILD_DIR) $(CPPCHECK_TARGET); \ + elif test `$(CPPCHECK_CMD) --version | sed -e 's/\./ /g' | awk '{print ($$2 * 1000 + $$3)}'` -lt $(CPPCHECK_GE207_VER); then \ + $(CPPCHECK_CMD) $(CPPCHECK_BASE_OPT) $(CPPCHECK_DEFINE_OPT) $(CPPCHECK_INCDIR_OPT) $(CPPCHECK_ENABLE_OPT) $(CPPCHECK_IGNORE_OPT) $(CPPCHECK_GT204_ADD_OPT) --cppcheck-build-dir=$(CPPCHECK_BUILD_DIR) $(CPPCHECK_TARGET); \ + elif test `$(CPPCHECK_CMD) --version | sed -e 's/\./ /g' | awk '{print ($$2 * 1000 + $$3)}'` -lt $(CPPCHECK_GE211_VER); then \ + $(CPPCHECK_CMD) $(CPPCHECK_BASE_OPT) $(CPPCHECK_DEFINE_OPT) $(CPPCHECK_INCDIR_OPT) $(CPPCHECK_ENABLE_OPT) $(CPPCHECK_IGNORE_OPT) $(CPPCHECK_GT204_ADD_OPT) $(CPPCHECK_GE207_ADD_OPT) --cppcheck-build-dir=$(CPPCHECK_BUILD_DIR) $(CPPCHECK_TARGET); \ + else \ + $(CPPCHECK_CMD) $(CPPCHECK_BASE_OPT) $(CPPCHECK_DEFINE_OPT) $(CPPCHECK_INCDIR_OPT) $(CPPCHECK_ENABLE_OPT) $(CPPCHECK_IGNORE_OPT) $(CPPCHECK_GT204_ADD_OPT) $(CPPCHECK_GE207_ADD_OPT) $(CPPCHECK_GE211_ADD_OPT) --cppcheck-build-dir=$(CPPCHECK_BUILD_DIR) $(CPPCHECK_TARGET); \ + fi; \ rm -rf $(CPPCHECK_BUILD_DIR); \ fi; \ else \ @@ -81,16 +108,17 @@ SHELLCHECK_FILES_SH = `grep -ril '^\#!/bin/sh' . | grep '\.sh' | grep -v '\ SHELLCHECK_FILES_INCLUDE_SH = `grep -Lir '^\#!/bin/sh' . | grep '\.sh' | grep -v '\.log' | grep -v '/\.git/' | grep -v '/rpmbuild/' | grep -v '/debian_build/' | grep -v '/autom4te.cache/' | grep -v '/m4/' | grep -v '/install-sh' | grep -v '/ltmain.sh' | tr '\n' ' '` shellcheck: - @if type shellcheck > /dev/null 2>&1; then \ + @set -e; \ + if type shellcheck > /dev/null 2>&1; then \ echo "*** Check all files with ShellCheck"; \ if [ -n "$(SHELLCHECK_FILES_NO_SH)" ]; then \ - LC_ALL=C.UTF-8 $(SHELLCHECK_CMD) $(SHELLCHECK_BASE_OPT) $(SHELLCHECK_IGN_OPT) $(SHELLCHECK_FILES_NO_SH) || exit 1; \ + LC_ALL=C.UTF-8 $(SHELLCHECK_CMD) $(SHELLCHECK_BASE_OPT) $(SHELLCHECK_IGN_OPT) $(SHELLCHECK_FILES_NO_SH); \ fi; \ if [ -n "$(SHELLCHECK_FILES_SH)" ]; then \ - LC_ALL=C.UTF-8 $(SHELLCHECK_CMD) $(SHELLCHECK_BASE_OPT) $(SHELLCHECK_IGN_OPT) $(SHELLCHECK_FILES_SH) || exit 1; \ + LC_ALL=C.UTF-8 $(SHELLCHECK_CMD) $(SHELLCHECK_BASE_OPT) $(SHELLCHECK_IGN_OPT) $(SHELLCHECK_FILES_SH); \ fi; \ if [ -n "$(SHELLCHECK_FILES_INCLUDE_SH)" ]; then \ - LC_ALL=C.UTF-8 $(SHELLCHECK_CMD) $(SHELLCHECK_BASE_OPT) $(SHELLCHECK_INCLUDE_IGN_OPT) $(SHELLCHECK_FILES_INCLUDE_SH) || exit 1; \ + LC_ALL=C.UTF-8 $(SHELLCHECK_CMD) $(SHELLCHECK_BASE_OPT) $(SHELLCHECK_INCLUDE_IGN_OPT) $(SHELLCHECK_FILES_INCLUDE_SH); \ fi; \ echo " -> No error was detected."; \ echo ""; \ diff --git a/buildutils/chmpx.spec.in b/buildutils/chmpx.spec.in index 5104700..3e42cf3 100644 --- a/buildutils/chmpx.spec.in +++ b/buildutils/chmpx.spec.in @@ -58,11 +58,11 @@ License: @PKGLICENSE@ @RPMPKG_GROUP@ URL: https://@GIT_DOMAIN@/@GIT_ORG@/@PACKAGE_NAME@ Source0: https://@GIT_DOMAIN@/@GIT_ORG@/@PACKAGE_NAME@/archive/%{gittag}/%{name}-%{version}.tar.gz -Requires: k2hash%{?_isa} >= 1.0.92, libfullock%{?_isa} >= 1.0.57, nss-tools +Requires: k2hash%{?_isa} >= 1.0.93, libfullock%{?_isa} >= 1.0.59, nss-tools %if 0%{?rhel} == 6 -BuildRequires: git-core gcc-c++ make libtool k2hash-devel >= 1.0.92, libfullock-devel >= 1.0.57, libyaml-devel, nss-devel +BuildRequires: git-core gcc-c++ make libtool k2hash-devel >= 1.0.93, libfullock-devel >= 1.0.59, libyaml-devel, nss-devel %else -BuildRequires: systemd git-core gcc-c++ make libtool k2hash-devel >= 1.0.92, libfullock-devel >= 1.0.57, libyaml-devel, nss-devel +BuildRequires: systemd git-core gcc-c++ make libtool k2hash-devel >= 1.0.93, libfullock-devel >= 1.0.59, libyaml-devel, nss-devel %endif %description @@ -134,7 +134,7 @@ rm -rf %{buildroot} # %package devel Summary: @SHORTDESC@ (development) -Requires: %{name}%{?_isa} = %{version}-%{release}, k2hash-devel%{?_isa} >= 1.0.92, libfullock-devel%{?_isa} >= 1.0.57, libyaml-devel, nss-devel +Requires: %{name}%{?_isa} = %{version}-%{release}, k2hash-devel%{?_isa} >= 1.0.93, libfullock-devel%{?_isa} >= 1.0.59, libyaml-devel, nss-devel %description devel Development package for building with @PACKAGE_NAME@ shared library. diff --git a/buildutils/control.in b/buildutils/control.in index e54338a..83fca7d 100644 --- a/buildutils/control.in +++ b/buildutils/control.in @@ -2,7 +2,7 @@ Source: @PACKAGE_NAME@ Section: net Priority: optional Maintainer: @DEV_NAME@ <@DEV_EMAIL@> -Build-Depends: @DEBHELPER_DEP@, k2hash-dev (>= 1.0.92), libfullock-dev (>= 1.0.57), libyaml-dev, gnutls-dev +Build-Depends: @DEBHELPER_DEP@, k2hash-dev (>= 1.0.93), libfullock-dev (>= 1.0.59), libyaml-dev, gnutls-dev Standards-Version: 3.9.8 Homepage: https://@GIT_DOMAIN@/@GIT_ORG@/@GIT_REPO@ Vcs-Git: git://@GIT_DOMAIN@/@GIT_ORG@/@GIT_REPO@.git @@ -11,7 +11,7 @@ Vcs-Browser: https://@GIT_DOMAIN@/@GIT_ORG@/@GIT_REPO@ Package: @PACKAGE_NAME@-dev Section: devel Architecture: amd64 -Depends: ${misc:Depends}, @PACKAGE_NAME@ (= ${binary:Version}), k2hash-dev (>= 1.0.92), libfullock-dev (>= 1.0.57), libyaml-dev, gnutls-dev +Depends: ${misc:Depends}, @PACKAGE_NAME@ (= ${binary:Version}), k2hash-dev (>= 1.0.93), libfullock-dev (>= 1.0.59), libyaml-dev, gnutls-dev Description: @SHORTDESC@ (development) Development package for building with @PACKAGE_NAME@ shared library. This package has header files and symbols for it. @@ -19,6 +19,6 @@ Description: @SHORTDESC@ (development) Package: @PACKAGE_NAME@ Section: net Architecture: amd64 -Depends: ${shlibs:Depends}, ${misc:Depends}, init-system-helpers (>= 1.14), k2hash (>= 1.0.92), libfullock (>= 1.0.57) +Depends: ${shlibs:Depends}, ${misc:Depends}, init-system-helpers (>= 1.14), k2hash (>= 1.0.93), libfullock (>= 1.0.59) Description: @SHORTDESC@ @DEBLONGDESC@ diff --git a/configure.ac b/configure.ac index e419971..95c77aa 100644 --- a/configure.ac +++ b/configure.ac @@ -235,8 +235,8 @@ AC_ARG_ENABLE(check-depend-libs, esac] ) AS_IF([test ${check_depend_libs} = 1], [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)]) -AS_IF([test ${check_depend_libs} = 1], [PKG_CHECK_MODULES([k2hash], [libk2hash >= 1.0.92], [], [AC_MSG_ERROR(not found k2hash package)])]) -AS_IF([test ${check_depend_libs} = 1], [PKG_CHECK_MODULES([fullock], [libfullock >= 1.0.57], [], [AC_MSG_ERROR(not found libfullock package)])]) +AS_IF([test ${check_depend_libs} = 1], [PKG_CHECK_MODULES([k2hash], [libk2hash >= 1.0.93], [], [AC_MSG_ERROR(not found k2hash package)])]) +AS_IF([test ${check_depend_libs} = 1], [PKG_CHECK_MODULES([fullock], [libfullock >= 1.0.59], [], [AC_MSG_ERROR(not found libfullock package)])]) # # CFLAGS/CXXFLAGS diff --git a/lib/chmcntrl.cc b/lib/chmcntrl.cc index 15537e6..ac97a2d 100644 --- a/lib/chmcntrl.cc +++ b/lib/chmcntrl.cc @@ -142,6 +142,8 @@ ChmEventBase* ChmCntrl::FindEventBaseObj(int fd) ChmEventBase* pEvObj = NULL; for(evobj_map_t::const_iterator iter = evobjmap.begin(); iter != evobjmap.end(); ++iter){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm if((iter->second)->IsEventQueueFd(fd)){ pEvObj = iter->second; break; @@ -158,6 +160,8 @@ bool ChmCntrl::GetEventBaseObjType(const ChmEventBase* pEvObj, EVOBJTYPE& type) bool result = false; for(evobj_map_t::const_iterator iter = evobjmap.begin(); iter != evobjmap.end(); ++iter){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm if(iter->second == pEvObj){ type = CVT_EVMAP_TO_EVOBJTYPE(iter->first); result = true; @@ -510,7 +514,6 @@ bool ChmCntrl::EventLoop(void) if(0L == ImData.GetUpServerCount()){ // Check any server up if(pEventSock->InitialAllServerStatus()){ - // cppcheck-suppress knownConditionTrueFalse if(0L < ImData.GetUpServerCount()){ // Try to connect servers //MSG_CHMPRN("Try to connect servers on RING(mode is SLAVE)."); @@ -531,7 +534,6 @@ bool ChmCntrl::EventLoop(void) // [NOTE] // This case is that there are no other server node up. if(pEventSock->InitialAllServerStatus()){ - // cppcheck-suppress knownConditionTrueFalse if(1L < ImData.GetUpServerCount()){ // Try to connect servers //MSG_CHMPRN("Try to connect servers on RING(mode is SERVER)."); @@ -642,7 +644,7 @@ bool ChmCntrl::Processing(PCOMPKT pComPkt, EVOBJTYPE call_ev_type) }else if(COM_C2PX == pComPkt->head.type || COM_PX2C == pComPkt->head.type){ // Input from MQ, so processing do on MQ // - PPXCLT_ALL pCltAll = CVT_CLT_ALL_PTR_PXCOMPKT(pComPkt); + const PPXCLT_ALL pCltAll = CVT_CLT_ALL_PTR_PXCOMPKT(pComPkt); if(IS_PXCLT_TYPE(pCltAll, CHMPX_CLT_JOIN_NOTIFY)){ // CHMPX_CLT_JOIN_NOTIFY type is processing by ChmEventSock. pProcessObj = GetEventBaseObj(EVOBJ_TYPE_EVSOCK); diff --git a/lib/chmconf.cc b/lib/chmconf.cc index 966b131..1b67f95 100644 --- a/lib/chmconf.cc +++ b/lib/chmconf.cc @@ -1236,6 +1236,8 @@ bool CHMConf::IsSsl(void) const while(!fullock::flck_trylock_noshared_mutex(&CHMConf::lockval)); // LOCK for(chmnode_cfginfos_t::const_iterator iter = pchmcfginfo->servers.begin(); iter != pchmcfginfo->servers.end(); ++iter){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm if(iter->is_ssl){ fullock::flck_unlock_noshared_mutex(&CHMConf::lockval); // UNLOCK return true; @@ -1288,6 +1290,8 @@ bool CHMIniConf::ReadFileContents(const string& filename, strlst_t& linelst, str // found include. bool found_same_file = false; for(strlst_t::const_iterator iter = allfiles.begin(); iter != allfiles.end(); ++iter){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm if(value == (*iter)){ found_same_file = true; break; @@ -1825,7 +1829,7 @@ bool CHMIniConf::LoadConfiguration(CHMCFGINFO& chmcfginfo) const } } if(CHM_MAX_PATH_LEN <= chmcfgraw.global[INICFG_CAPATH_STR].length()){ - ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zd) is over max length(1024).", cfgfile.c_str(), INICFG_CAPATH_STR, chmcfgraw.global[INICFG_CAPATH_STR].c_str(), INICFG_GLOBAL_SEC_STR, chmcfgraw.global[INICFG_CAPATH_STR].length()); + ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zu) is over max length(1024).", cfgfile.c_str(), INICFG_CAPATH_STR, chmcfgraw.global[INICFG_CAPATH_STR].c_str(), INICFG_GLOBAL_SEC_STR, chmcfgraw.global[INICFG_CAPATH_STR].length()); return false; } ccvals.capath = chmcfgraw.global[INICFG_CAPATH_STR]; @@ -1847,7 +1851,7 @@ bool CHMIniConf::LoadConfiguration(CHMCFGINFO& chmcfginfo) const // allow any string } if(CHM_MAX_PATH_LEN <= chmcfgraw.global[INICFG_SERVER_CERT_STR].length()){ - ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zd) is over max length(1024).", cfgfile.c_str(), INICFG_SERVER_CERT_STR, chmcfgraw.global[INICFG_SERVER_CERT_STR].c_str(), INICFG_GLOBAL_SEC_STR, chmcfgraw.global[INICFG_SERVER_CERT_STR].length()); + ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zu) is over max length(1024).", cfgfile.c_str(), INICFG_SERVER_CERT_STR, chmcfgraw.global[INICFG_SERVER_CERT_STR].c_str(), INICFG_GLOBAL_SEC_STR, chmcfgraw.global[INICFG_SERVER_CERT_STR].length()); return false; } ccvals.server_cert = chmcfgraw.global[INICFG_SERVER_CERT_STR]; @@ -1869,7 +1873,7 @@ bool CHMIniConf::LoadConfiguration(CHMCFGINFO& chmcfginfo) const // allow any string } if(CHM_MAX_PATH_LEN <= chmcfgraw.global[INICFG_SERVER_PRIKEY_STR].length()){ - ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zd) is over max length(1024).", cfgfile.c_str(), INICFG_SERVER_PRIKEY_STR, chmcfgraw.global[INICFG_SERVER_PRIKEY_STR].c_str(), INICFG_GLOBAL_SEC_STR, chmcfgraw.global[INICFG_SERVER_PRIKEY_STR].length()); + ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zu) is over max length(1024).", cfgfile.c_str(), INICFG_SERVER_PRIKEY_STR, chmcfgraw.global[INICFG_SERVER_PRIKEY_STR].c_str(), INICFG_GLOBAL_SEC_STR, chmcfgraw.global[INICFG_SERVER_PRIKEY_STR].length()); return false; } ccvals.server_prikey = chmcfgraw.global[INICFG_SERVER_PRIKEY_STR]; @@ -1888,7 +1892,7 @@ bool CHMIniConf::LoadConfiguration(CHMCFGINFO& chmcfginfo) const // allow any string } if(CHM_MAX_PATH_LEN <= chmcfgraw.global[INICFG_SLAVE_CERT_STR].length()){ - ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zd) is over max length(1024).", cfgfile.c_str(), INICFG_SLAVE_CERT_STR, chmcfgraw.global[INICFG_SLAVE_CERT_STR].c_str(), INICFG_GLOBAL_SEC_STR, chmcfgraw.global[INICFG_SLAVE_CERT_STR].length()); + ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zu) is over max length(1024).", cfgfile.c_str(), INICFG_SLAVE_CERT_STR, chmcfgraw.global[INICFG_SLAVE_CERT_STR].c_str(), INICFG_GLOBAL_SEC_STR, chmcfgraw.global[INICFG_SLAVE_CERT_STR].length()); return false; } ccvals.slave_cert = chmcfgraw.global[INICFG_SLAVE_CERT_STR]; @@ -1907,7 +1911,7 @@ bool CHMIniConf::LoadConfiguration(CHMCFGINFO& chmcfginfo) const // allow any string } if(CHM_MAX_PATH_LEN <= chmcfgraw.global[INICFG_SLAVE_PRIKEY_STR].length()){ - ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zd) is over max length(1024).", cfgfile.c_str(), INICFG_SLAVE_PRIKEY_STR, chmcfgraw.global[INICFG_SLAVE_PRIKEY_STR].c_str(), INICFG_GLOBAL_SEC_STR, chmcfgraw.global[INICFG_SLAVE_PRIKEY_STR].length()); + ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zu) is over max length(1024).", cfgfile.c_str(), INICFG_SLAVE_PRIKEY_STR, chmcfgraw.global[INICFG_SLAVE_PRIKEY_STR].c_str(), INICFG_GLOBAL_SEC_STR, chmcfgraw.global[INICFG_SLAVE_PRIKEY_STR].length()); return false; } ccvals.slave_prikey = chmcfgraw.global[INICFG_SLAVE_PRIKEY_STR]; @@ -1940,7 +1944,7 @@ bool CHMIniConf::LoadConfiguration(CHMCFGINFO& chmcfginfo) const return false; } if(CHM_MAX_PATH_LEN <= chmcfgraw.global[INICFG_NSSDB_DIR_STR].length()){ - ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zd) is over max length(1024).", cfgfile.c_str(), INICFG_NSSDB_DIR_STR, chmcfgraw.global[INICFG_NSSDB_DIR_STR].c_str(), INICFG_GLOBAL_SEC_STR, chmcfgraw.global[INICFG_NSSDB_DIR_STR].length()); + ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zu) is over max length(1024).", cfgfile.c_str(), INICFG_NSSDB_DIR_STR, chmcfgraw.global[INICFG_NSSDB_DIR_STR].c_str(), INICFG_GLOBAL_SEC_STR, chmcfgraw.global[INICFG_NSSDB_DIR_STR].length()); return false; } chmcfginfo.nssdb_dir = chmcfgraw.global[INICFG_NSSDB_DIR_STR]; @@ -2163,7 +2167,7 @@ bool CHMIniConf::LoadConfiguration(CHMCFGINFO& chmcfginfo) const } } if(CHM_MAX_PATH_LEN <= (*iter)[INICFG_CAPATH_STR].length()){ - ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zd) is over max length(1024).", cfgfile.c_str(), INICFG_CAPATH_STR, (*iter)[INICFG_CAPATH_STR].c_str(), INICFG_GLOBAL_SEC_STR, (*iter)[INICFG_CAPATH_STR].length()); + ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zu) is over max length(1024).", cfgfile.c_str(), INICFG_CAPATH_STR, (*iter)[INICFG_CAPATH_STR].c_str(), INICFG_GLOBAL_SEC_STR, (*iter)[INICFG_CAPATH_STR].length()); return false; } svrnode.capath = (*iter)[INICFG_CAPATH_STR].c_str(); @@ -2187,7 +2191,7 @@ bool CHMIniConf::LoadConfiguration(CHMCFGINFO& chmcfginfo) const // allow any string } if(CHM_MAX_PATH_LEN <= (*iter)[INICFG_SERVER_CERT_STR].length()){ - ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zd) is over max length(1024).", cfgfile.c_str(), INICFG_SERVER_CERT_STR, (*iter)[INICFG_SERVER_CERT_STR].c_str(), INICFG_GLOBAL_SEC_STR, (*iter)[INICFG_SERVER_CERT_STR].length()); + ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zu) is over max length(1024).", cfgfile.c_str(), INICFG_SERVER_CERT_STR, (*iter)[INICFG_SERVER_CERT_STR].c_str(), INICFG_GLOBAL_SEC_STR, (*iter)[INICFG_SERVER_CERT_STR].length()); return false; } svrnode.server_cert = (*iter)[INICFG_SERVER_CERT_STR].c_str(); @@ -2212,7 +2216,7 @@ bool CHMIniConf::LoadConfiguration(CHMCFGINFO& chmcfginfo) const // allow any string } if(CHM_MAX_PATH_LEN <= (*iter)[INICFG_SERVER_PRIKEY_STR].length()){ - ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zd) is over max length(1024).", cfgfile.c_str(), INICFG_SERVER_PRIKEY_STR, (*iter)[INICFG_SERVER_PRIKEY_STR].c_str(), INICFG_GLOBAL_SEC_STR, (*iter)[INICFG_SERVER_PRIKEY_STR].length()); + ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zu) is over max length(1024).", cfgfile.c_str(), INICFG_SERVER_PRIKEY_STR, (*iter)[INICFG_SERVER_PRIKEY_STR].c_str(), INICFG_GLOBAL_SEC_STR, (*iter)[INICFG_SERVER_PRIKEY_STR].length()); return false; } svrnode.server_prikey = (*iter)[INICFG_SERVER_PRIKEY_STR].c_str(); @@ -2242,7 +2246,7 @@ bool CHMIniConf::LoadConfiguration(CHMCFGINFO& chmcfginfo) const // allow any string } if(CHM_MAX_PATH_LEN <= (*iter)[INICFG_SLAVE_CERT_STR].length()){ - ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zd) is over max length(1024).", cfgfile.c_str(), INICFG_SLAVE_CERT_STR, (*iter)[INICFG_SLAVE_CERT_STR].c_str(), INICFG_GLOBAL_SEC_STR, (*iter)[INICFG_SLAVE_CERT_STR].length()); + ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zu) is over max length(1024).", cfgfile.c_str(), INICFG_SLAVE_CERT_STR, (*iter)[INICFG_SLAVE_CERT_STR].c_str(), INICFG_GLOBAL_SEC_STR, (*iter)[INICFG_SLAVE_CERT_STR].length()); return false; } svrnode.slave_cert = (*iter)[INICFG_SLAVE_CERT_STR].c_str(); @@ -2264,7 +2268,7 @@ bool CHMIniConf::LoadConfiguration(CHMCFGINFO& chmcfginfo) const // allow any string } if(CHM_MAX_PATH_LEN <= (*iter)[INICFG_SLAVE_PRIKEY_STR].length()){ - ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zd) is over max length(1024).", cfgfile.c_str(), INICFG_SLAVE_PRIKEY_STR, (*iter)[INICFG_SLAVE_PRIKEY_STR].c_str(), INICFG_GLOBAL_SEC_STR, (*iter)[INICFG_SLAVE_PRIKEY_STR].length()); + ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zu) is over max length(1024).", cfgfile.c_str(), INICFG_SLAVE_PRIKEY_STR, (*iter)[INICFG_SLAVE_PRIKEY_STR].c_str(), INICFG_GLOBAL_SEC_STR, (*iter)[INICFG_SLAVE_PRIKEY_STR].length()); return false; } svrnode.slave_prikey = (*iter)[INICFG_SLAVE_PRIKEY_STR].c_str(); @@ -2486,7 +2490,7 @@ bool CHMIniConf::LoadConfiguration(CHMCFGINFO& chmcfginfo) const } } if(CHM_MAX_PATH_LEN <= (*iter)[INICFG_CAPATH_STR].length()){ - ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zd) is over max length(1024).", cfgfile.c_str(), INICFG_CAPATH_STR, (*iter)[INICFG_CAPATH_STR].c_str(), INICFG_SLVNODE_SEC_STR, (*iter)[INICFG_CAPATH_STR].length()); + ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zu) is over max length(1024).", cfgfile.c_str(), INICFG_CAPATH_STR, (*iter)[INICFG_CAPATH_STR].c_str(), INICFG_SLVNODE_SEC_STR, (*iter)[INICFG_CAPATH_STR].length()); return false; } slvnode.capath = (*iter)[INICFG_CAPATH_STR].c_str(); @@ -2515,7 +2519,7 @@ bool CHMIniConf::LoadConfiguration(CHMCFGINFO& chmcfginfo) const // allow any string } if(CHM_MAX_PATH_LEN <= (*iter)[INICFG_SLAVE_CERT_STR].length()){ - ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zd) is over max length(1024).", cfgfile.c_str(), INICFG_SLAVE_CERT_STR, (*iter)[INICFG_SLAVE_CERT_STR].c_str(), INICFG_SLVNODE_SEC_STR, (*iter)[INICFG_SLAVE_CERT_STR].length()); + ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zu) is over max length(1024).", cfgfile.c_str(), INICFG_SLAVE_CERT_STR, (*iter)[INICFG_SLAVE_CERT_STR].c_str(), INICFG_SLVNODE_SEC_STR, (*iter)[INICFG_SLAVE_CERT_STR].length()); return false; } slvnode.slave_cert = (*iter)[INICFG_SLAVE_CERT_STR].c_str(); @@ -2544,7 +2548,7 @@ bool CHMIniConf::LoadConfiguration(CHMCFGINFO& chmcfginfo) const // check private key in ssl class. } if(CHM_MAX_PATH_LEN <= (*iter)[INICFG_SLAVE_PRIKEY_STR].length()){ - ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zd) is over max length(1024).", cfgfile.c_str(), INICFG_SLAVE_PRIKEY_STR, (*iter)[INICFG_SLAVE_PRIKEY_STR].c_str(), INICFG_SLVNODE_SEC_STR, (*iter)[INICFG_SLAVE_PRIKEY_STR].length()); + ERR_CHMPRN("configuration file(%s) have \"%s\" value(%s) in %s section, but it is length(%zu) is over max length(1024).", cfgfile.c_str(), INICFG_SLAVE_PRIKEY_STR, (*iter)[INICFG_SLAVE_PRIKEY_STR].c_str(), INICFG_SLVNODE_SEC_STR, (*iter)[INICFG_SLAVE_PRIKEY_STR].length()); return false; } slvnode.slave_prikey = (*iter)[INICFG_SLAVE_PRIKEY_STR].c_str(); diff --git a/lib/chmdbg.h b/lib/chmdbg.h index ba5642c..67864c5 100644 --- a/lib/chmdbg.h +++ b/lib/chmdbg.h @@ -51,31 +51,37 @@ bool UnsetChmDbgFile(void); //--------------------------------------------------------- // Debugging Macros //--------------------------------------------------------- -#define ChmDbgMode_STR(mode) CHMDBG_SILENT == mode ? "SLT" : \ - CHMDBG_ERR == mode ? "ERR" : \ - CHMDBG_WARN == mode ? "WAN" : \ - CHMDBG_MSG == mode ? "MSG" : \ - CHMDBG_DUMP == mode ? "DMP" : "" +#define STR_CHMDBG_SILENT "SLT" +#define STR_CHMDBG_ERR "ERR" +#define STR_CHMDBG_WARN "WAN" +#define STR_CHMDBG_MSG "MSG" +#define STR_CHMDBG_DUMP "DMP" -#define LOW_CHMPRINT(mode, fmt, ...) \ - fprintf((chm_dbg_fp ? chm_dbg_fp : stderr), "[CHMPX-%s] %s(%d) : " fmt "%s\n", ChmDbgMode_STR(mode), __func__, __LINE__, __VA_ARGS__); +#define ChmDbgMode_STR(mode) CHMDBG_SILENT == mode ? STR_CHMDBG_SILENT : \ + CHMDBG_ERR == mode ? STR_CHMDBG_ERR : \ + CHMDBG_WARN == mode ? STR_CHMDBG_WARN : \ + CHMDBG_MSG == mode ? STR_CHMDBG_MSG : \ + CHMDBG_DUMP == mode ? STR_CHMDBG_DUMP : "" -#define CHMPRINT(mode, ...) \ - if((chm_debug_mode & mode) == mode){ \ - LOW_CHMPRINT(mode, __VA_ARGS__); \ +#define LOW_CHMPRINT(strmode, fmt, ...) \ + fprintf((chm_dbg_fp ? chm_dbg_fp : stderr), "[CHMPX-%s] %s(%d) : " fmt "%s\n", strmode, __func__, __LINE__, __VA_ARGS__); + +#define CHMPRINT(mode, strmode, ...) \ + if((static_cast(chm_debug_mode) & static_cast(mode)) == static_cast(mode)){ \ + LOW_CHMPRINT(strmode, __VA_ARGS__); \ } -#define SLT_CHMPRN(...) CHMPRINT(CHMDBG_SILENT, ##__VA_ARGS__, "") // This means nothing... -#define ERR_CHMPRN(...) CHMPRINT(CHMDBG_ERR, ##__VA_ARGS__, "") -#define WAN_CHMPRN(...) CHMPRINT(CHMDBG_WARN, ##__VA_ARGS__, "") -#define MSG_CHMPRN(...) CHMPRINT(CHMDBG_MSG, ##__VA_ARGS__, "") -#define DMP_CHMPRN(...) CHMPRINT(CHMDBG_DUMP, ##__VA_ARGS__, "") +#define SLT_CHMPRN(...) CHMPRINT(CHMDBG_SILENT, STR_CHMDBG_SILENT, ##__VA_ARGS__, "") // This means nothing... +#define ERR_CHMPRN(...) CHMPRINT(CHMDBG_ERR, STR_CHMDBG_ERR, ##__VA_ARGS__, "") +#define WAN_CHMPRN(...) CHMPRINT(CHMDBG_WARN, STR_CHMDBG_WARN, ##__VA_ARGS__, "") +#define MSG_CHMPRN(...) CHMPRINT(CHMDBG_MSG, STR_CHMDBG_MSG, ##__VA_ARGS__, "") +#define DMP_CHMPRN(...) CHMPRINT(CHMDBG_DUMP, STR_CHMDBG_DUMP, ##__VA_ARGS__, "") // // If using following macro, need to specify include time.h. // #define CLOCKTIME_CHMPRN(phead) \ - if((chm_debug_mode & CHMDBG_DUMP) == CHMDBG_DUMP){ \ + if(((static_cast(chm_debug_mode) & (static_cast(CHMDBG_DUMP)) == (static_cast(CHMDBG_DUMP)){ \ struct timespec reqtime; \ if(-1 == clock_gettime(CLOCK_REALTIME_COARSE, &reqtime)){ \ fprintf((chm_dbg_fp ? chm_dbg_fp : stderr), "[CHMPX-TIME-%s] ---s ---ms ---us ---ns\n", (phead ? phead : "DBG")); \ diff --git a/lib/chmeventmq.cc b/lib/chmeventmq.cc index 13185e7..f0f2e52 100644 --- a/lib/chmeventmq.cc +++ b/lib/chmeventmq.cc @@ -425,7 +425,7 @@ msgid_t ChmEventMq::ComposeSerialMsgid(const msgid_t msgid, const serial_t seria if(IsEmpty()){ return CHM_INVALID_MSGID; } - ChmIMData* pImData = pChmCntrl->GetImDataObj(); + const ChmIMData* pImData = pChmCntrl->GetImDataObj(); return COMPOSE64(static_cast(serial | (is_ack ? (ack_success ? MQ_ACK_SUCCESS : MQ_ACK_FAILURE) : 0L)), (msgid - pImData->GetBaseMsgId())); } @@ -438,7 +438,7 @@ bool ChmEventMq::DecomposeSerialMsgid(const msgid_t msgid, COMPOSEDMSGID& compos if(CHM_INVALID_MSGID == msgid){ return false; } - ChmIMData* pImData = pChmCntrl->GetImDataObj(); + const ChmIMData* pImData = pChmCntrl->GetImDataObj(); serial_t tmp = (static_cast(msgid) & MASK64_HIBIT) >> 32; composed.msgid = pImData->GetBaseMsgId() + (msgid & MASK64_LOWBIT); @@ -2068,6 +2068,9 @@ bool ChmEventMq::PxCltReceiveMergeGetLastTime(PCOMHEAD pComHead, PPXCLT_ALL pClt struct timespec updatets = {0, 0}; if(mlastfunc){ chmpx_h handle = reinterpret_cast(pChmCntrl); + + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownPointerToBool if(!mlastfunc(handle, &updatets)){ ERR_CHMPRN("Failed to get lastest update time, but continue with zero value for merging."); INIT_TIMESPEC(&updatets); @@ -2291,9 +2294,7 @@ bool ChmEventMq::PxCltReceiveRequestUpdateData(PCOMHEAD pComHead, PPXCLT_ALL pCl // stack merge parameter while(!fullock::flck_trylock_noshared_mutex(&mparam_list_lockval)); // LOCK merge_param_list.push_back(pUpdateDataParam); - if(!notify_merge_update){ - notify_merge_update = true; - } + notify_merge_update = true; // Force to set fullock::flck_unlock_noshared_mutex(&mparam_list_lockval); // UNLOCK // run thread @@ -2412,7 +2413,7 @@ bool ChmEventMq::PxCltReceiveResponseUpdateData(PCOMHEAD pComHead, PPXCLT_ALL pC ERR_CHMPRN("Received CHMPX_CLT_RES_UPDATEDATA is wrong."); return false; } - unsigned char* pbindata = CHM_ABS(pResUpdateData, pResUpdateData->byptr, unsigned char*); + const unsigned char* pbindata = CHM_ABS(pResUpdateData, pResUpdateData->byptr, unsigned char*); // transfer return pChmCntrl->MergeResponseUpdateData(pResUpdateData->chmpxid, pResUpdateData->length, pbindata, &(pResUpdateData->ts)); @@ -2519,6 +2520,8 @@ bool ChmEventMq::PxCltReceiveSetUpdateData(PCOMHEAD pComHead, PPXCLT_ALL pCltAll unsigned char* pbindata = CHM_ABS(pSetUpdateData, pSetUpdateData->byptr, unsigned char*); // run callback function + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownPointerToBool return msetfunc(reinterpret_cast(pChmCntrl), pSetUpdateData->length, pbindata, &(pSetUpdateData->ts)); } diff --git a/lib/chmeventsock.cc b/lib/chmeventsock.cc index a3fe24e..75beb92 100644 --- a/lib/chmeventsock.cc +++ b/lib/chmeventsock.cc @@ -562,7 +562,7 @@ bool ChmEventSock::RawSend(int sock, ChmSSSession ssl, PCOMPKT pComPkt, bool& is ERR_CHMPRN("Length(%zu) in PCOMPKT is wrong.", length); return false; } - unsigned char* pbydata = reinterpret_cast(pComPkt); + const unsigned char* pbydata = reinterpret_cast(pComPkt); // send return ChmEventSock::RawSend(sock, ssl, pbydata, length, is_closed, is_blocking, retrycnt, waittime); @@ -1430,8 +1430,8 @@ PCOMPKT ChmEventSock::DuplicateComPkt(PCOMPKT pComPkt) // copy after compkt if(sizeof(COMPKT) < pComPkt->length){ - unsigned char* psrc = reinterpret_cast(pComPkt) + sizeof(COMPKT); - unsigned char* pdest = reinterpret_cast(pDupPkt) + sizeof(COMPKT); + const unsigned char* psrc = reinterpret_cast(pComPkt) + sizeof(COMPKT); + unsigned char* pdest = reinterpret_cast(pDupPkt) + sizeof(COMPKT); memcpy(pdest, psrc, (pComPkt->length - sizeof(COMPKT))); } return pDupPkt; @@ -1647,6 +1647,8 @@ bool ChmEventSock::MergeWorkerFunc(void* common_param, chmthparam_t wp_param) while(!fullock::flck_trylock_noshared_mutex(&(pThis->mergeidmap_lockval))); // LOCK for(mergeidmap_t::const_iterator iter = pThis->mergeidmap.begin(); iter != pThis->mergeidmap.end(); ++iter){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm if(!IS_PXCOM_REQ_UPDATE_RESULT(iter->second)){ is_all_finish = false; break; @@ -2524,6 +2526,8 @@ bool ChmEventSock::GetLockedSendSock(chmpxid_t chmpxid, int& sock, bool is_check // try to lock existed socket for(socklist_t::const_iterator iter = socklist.begin(); iter != socklist.end(); ++iter){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm if(TryLockSendSock(*iter)){ // try to lock socket // Succeed to lock socket! sock = *iter; @@ -2547,6 +2551,8 @@ bool ChmEventSock::GetLockedSendSock(chmpxid_t chmpxid, int& sock, bool is_check } if(TryLockSendSock(*iter)){ // try to lock socket // get locked sock status. + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress constVariablePointer const PCHMSSSTAT pssstat = sendlockmap.get(*iter); if(pssstat && (pssstat->last_time + sock_pool_timeout) < nowtime){ // timeouted socket. @@ -3611,7 +3617,7 @@ bool ChmEventSock::ConnectServer(chmpxid_t chmpxid, int& sock, bool without_set_ ERR_CHMPRN("Object is not initialized."); return false; } - ChmIMData* pImData = pChmCntrl->GetImDataObj(); + const ChmIMData* pImData = pChmCntrl->GetImDataObj(); // [NOTE] // This method checks only existing socket to chmpxid. Do not check lock @@ -5565,6 +5571,7 @@ bool ChmEventSock::Processing(int sock, const char* pCommand) if(cmdarray.empty()){ MSG_CHMPRN("%s command does not have parameter, so use default value(dir=all, dev=all, count=all trace count).", strCommand.c_str()); }else{ + // cppcheck-suppress unmatchedSuppression // cppcheck-suppress knownConditionTrueFalse for(string strTmp = ""; !cmdarray.empty(); cmdarray.pop_front()){ strTmp = cmdarray.front(); @@ -5913,13 +5920,13 @@ bool ChmEventSock::MergeDone(void) bool ChmEventSock::IsAutoMerge(void) { - ChmIMData* pImData = pChmCntrl->GetImDataObj(); + const ChmIMData* pImData = pChmCntrl->GetImDataObj(); return pImData->IsAutoMerge(); } bool ChmEventSock::IsDoMerge(void) { - ChmIMData* pImData = pChmCntrl->GetImDataObj(); + const ChmIMData* pImData = pChmCntrl->GetImDataObj(); return pImData->IsDoMerge(); } @@ -6464,7 +6471,7 @@ bool ChmEventSock::RequestMergeSuspend(string* pstring) *pstring = CTL_RES_ERROR_COULD_NOT_SUSPEND; } return false; - }else if(startup_servicein){ + }else{ startup_servicein = false; } @@ -7094,9 +7101,9 @@ bool ChmEventSock::CtlComDump(string& strResponse) ERR_CHMPRN("Object is not initialized."); return false; } - ChmIMData* pImData = pChmCntrl->GetImDataObj(); + const ChmIMData* pImData = pChmCntrl->GetImDataObj(); + stringstream sstream; - stringstream sstream; pImData->Dump(sstream); strResponse = sstream.str(); @@ -7911,7 +7918,9 @@ bool ChmEventSock::PxComReceiveConinitReq(PCOMHEAD pComHead, PPXCOM_ALL pComAll, // old version comver = pComHead->version; - PPXCOM_CONINIT_REQ pConinitReq = CVT_COMPTR_CONINIT_REQ(pComAll); + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress constVariablePointer + const PPXCOM_CONINIT_REQ pConinitReq = CVT_COMPTR_CONINIT_REQ(pComAll); name.clear(); from_chmpxid= pConinitReq->chmpxid; @@ -9792,7 +9801,7 @@ bool ChmEventSock::PxComReceiveMergeSuspend(PCOMHEAD pComHead, PPXCOM_ALL pComAl if(!pImData->SuspendAutoMerge()){ WAN_CHMPRN("Could not change auto merging flag to suspend."); pResMergeSuspend->head.result = CHMPX_COM_RES_ERROR; - }else if(startup_servicein){ + }else{ startup_servicein = false; } } @@ -10548,7 +10557,7 @@ bool ChmEventSock::PxComReceiveResUpdateData(const PCOMHEAD pComHead, PPXCOM_ALL ERR_CHMPRN("Received CHMPX_COM_RES_UPDATEDATA command is something wrong."); return false; } - unsigned char* pdata = CHM_OFFSET(pResUpdateData, pResUpdateData->pdata_offset, unsigned char*); + const unsigned char* pdata = CHM_OFFSET(pResUpdateData, pResUpdateData->pdata_offset, unsigned char*); // transfer client return pChmCntrl->MergeSetUpdateData(pResUpdateData->length, pdata, &(pResUpdateData->ts)); diff --git a/lib/chmimdata.cc b/lib/chmimdata.cc index 52cc4f0..4e475b9 100644 --- a/lib/chmimdata.cc +++ b/lib/chmimdata.cc @@ -128,6 +128,8 @@ bool ChmIMData::CompareChmpxNameAndCustomSeed(const CHMPXSVR& src1, const CHMPXS ChmNetDb::Get()->GetHostnameList(src2.name, hostnames2, true); for(strlst_t::const_iterator iter1 = hostnames1.begin(); iter1 != hostnames1.end(); ++iter1){ for(strlst_t::const_iterator iter2 = hostnames2.begin(); iter2 != hostnames2.end(); ++iter2){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm if(0 == strcmp(iter1->c_str(), iter2->c_str())){ return true; } @@ -1893,6 +1895,8 @@ long ChmIMData::GetServerChmpxIdByBaseHash(chmhash_t basehash, chmpxidlist_t& ch bool found; found = false; for(chmpxidlist_t::const_iterator iter2 = chmpxids.begin(); iter2 != chmpxids.end(); ++iter2){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm if((*iter1) == (*iter2)){ found = true; break; diff --git a/lib/chmkvp.cc b/lib/chmkvp.cc index ebd721f..4006f67 100644 --- a/lib/chmkvp.cc +++ b/lib/chmkvp.cc @@ -214,9 +214,9 @@ bool ChmBinData::Put(unsigned char* bydata, bool is_cvt_hton) const return false; } - size_t datapos = sizeof(size_t); - size_t tmplen = (is_cvt_hton ? htobe64(length) : length); - unsigned char* bylen = reinterpret_cast(&tmplen); + size_t datapos = sizeof(size_t); + size_t tmplen = (is_cvt_hton ? htobe64(length) : length); + const unsigned char* bylen = reinterpret_cast(&tmplen); for(size_t cnt = 0; cnt < datapos; ++cnt){ // cppcheck-suppress objectIndex @@ -271,7 +271,7 @@ ChmKVPair::ChmKVPair(unsigned char* bykey, size_t keylen, unsigned char* byval, { } -ChmKVPair::ChmKVPair(ChmBinData* pKey, ChmBinData* pValue, bool is_duplicate) +ChmKVPair::ChmKVPair(const ChmBinData* pKey, const ChmBinData* pValue, bool is_duplicate) { if(pKey){ Set(*pKey, true, is_duplicate); diff --git a/lib/chmkvp.h b/lib/chmkvp.h index 00ea424..d7ec02b 100644 --- a/lib/chmkvp.h +++ b/lib/chmkvp.h @@ -78,7 +78,7 @@ class ChmKVPair public: explicit ChmKVPair(unsigned char* bykey = NULL, size_t keylen = 0L, unsigned char* byval = NULL, size_t vallen = 0L, bool is_duplicate = false); - ChmKVPair(ChmBinData* pKey, ChmBinData* pValue, bool is_duplicate = false); + ChmKVPair(const ChmBinData* pKey, const ChmBinData* pValue, bool is_duplicate = false); ChmKVPair(PCHMKVP pkvp, bool is_duplicate); virtual ~ChmKVPair(); diff --git a/lib/chmlockmap.tcc b/lib/chmlockmap.tcc index 712ffb8..0ae1f82 100644 --- a/lib/chmlockmap.tcc +++ b/lib/chmlockmap.tcc @@ -56,6 +56,8 @@ class chm_lock_map chm_lock_map(void) : lockval(FLCK_NOSHARED_MUTEX_VAL_UNLOCKED), pbasefunc(NULL), pbaseparam(NULL) {} public: + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress uninitMemberVar explicit chm_lock_map(const val_type& initval, chm_lock_map_erase_cb pfunc = NULL, void* pparam = NULL) : lockval(FLCK_NOSHARED_MUTEX_VAL_UNLOCKED), pbasefunc(pfunc), pbaseparam(pparam), emptyval(initval) {} virtual ~chm_lock_map(void) { clear(); } @@ -134,6 +136,8 @@ inline bool chm_lock_map::set(const key_type& key, const val fullock::flck_unlock_noshared_mutex(&lockval); return false; } + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownPointerToBool if(pbasefunc && !pbasefunc(iter, pbaseparam)){ fullock::flck_unlock_noshared_mutex(&lockval); return false; @@ -178,6 +182,8 @@ inline bool chm_lock_map::erase(const key_type& key) fullock::flck_unlock_noshared_mutex(&lockval); return false; } + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownPointerToBool if(pbasefunc && !pbasefunc(iter, pbaseparam)){ fullock::flck_unlock_noshared_mutex(&lockval); return false; @@ -215,6 +221,8 @@ inline bool chm_lock_map::clear(void) { while(!fullock::flck_trylock_noshared_mutex(&lockval)); for(iterator iter = basemap.begin(); iter != basemap.end(); basemap.erase(iter++)){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownPointerToBool if(pbasefunc && !pbasefunc(iter, pbaseparam)){ fullock::flck_unlock_noshared_mutex(&lockval); return false; diff --git a/lib/chmnetdb.cc b/lib/chmnetdb.cc index 88bdf6d..6796465 100644 --- a/lib/chmnetdb.cc +++ b/lib/chmnetdb.cc @@ -56,6 +56,8 @@ static void AddUniqueStringToList(const string& str, strlst_t& list, bool is_cle return; } for(strlst_t::const_iterator iter = list.begin(); iter != list.end(); ++iter){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm if((*iter) == str){ // already has same string. return; @@ -75,6 +77,8 @@ static void AddUniqueStringListToList(const strlst_t& addlist, strlst_t& list, b } bool found = false; for(strlst_t::const_iterator iter2 = list.begin(); iter2 != list.end(); ++iter2){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm if((*iter1) == (*iter2)){ found = true; break; diff --git a/lib/chmopts.cc b/lib/chmopts.cc index 8e44fc6..9a65060 100644 --- a/lib/chmopts.cc +++ b/lib/chmopts.cc @@ -37,7 +37,7 @@ using namespace std; //--------------------------------------------------------- // Constructor/Destructor //--------------------------------------------------------- -ChmOpts::ChmOpts(int argc, char** argv, const char* strsepchars) : sepchars(CHMEMPTYSTR(strsepchars) ? OPT_PARAM_SEP : strsepchars) +ChmOpts::ChmOpts(int argc, const char** argv, const char* strsepchars) : sepchars(CHMEMPTYSTR(strsepchars) ? OPT_PARAM_SEP : strsepchars) { if(argv && 0 < argc){ Initialize(argc, argv); @@ -51,7 +51,7 @@ ChmOpts::~ChmOpts(void) //--------------------------------------------------------- // Methods //--------------------------------------------------------- -bool ChmOpts::Initialize(int argc, char** argv) +bool ChmOpts::Initialize(int argc, const char** argv) { if(!argv || 0 == argc){ ERR_CHMPRN("Parameters are wrong."); diff --git a/lib/chmopts.h b/lib/chmopts.h index 7430fe2..d919470 100644 --- a/lib/chmopts.h +++ b/lib/chmopts.h @@ -35,10 +35,10 @@ class ChmOpts std::string sepchars; public: - explicit ChmOpts(int argc = 0, char** argv = NULL, const char* strsepchars = NULL); + explicit ChmOpts(int argc = 0, const char** argv = NULL, const char* strsepchars = NULL); virtual ~ChmOpts(); - bool Initialize(int argc, char** argv); + bool Initialize(int argc, const char** argv); bool Get(const char* popt, std::string& param); bool Get(const char* popt, strlst_t& params); bool Find(const char* popt) const; diff --git a/lib/chmpx.cc b/lib/chmpx.cc index 70390ab..8774488 100644 --- a/lib/chmpx.cc +++ b/lib/chmpx.cc @@ -569,9 +569,9 @@ unsigned char* cvt_kvp_bin(const PCHMKVP pkvp, size_t* plength) } // set key - size_t setpos = 0; - size_t tmplen = htobe64(pkvp->key.length); // To network byte order - unsigned char* bylen = reinterpret_cast(&tmplen); + size_t setpos = 0; + size_t tmplen = htobe64(pkvp->key.length); // To network byte order + const unsigned char* bylen = reinterpret_cast(&tmplen); for(size_t cnt = 0; cnt < sizeof(size_t); ++cnt){ // cppcheck-suppress objectIndex pResult[setpos++] = bylen[cnt]; diff --git a/lib/chmregex.cc b/lib/chmregex.cc index fafbbfa..548229d 100644 --- a/lib/chmregex.cc +++ b/lib/chmregex.cc @@ -382,6 +382,8 @@ bool IsInHostnameList(const char* target, strlst_t& hostname_list, string& found } // compare each host in expand host for(strlst_t::const_iterator one_target_list_iter = one_target_list.begin(); one_target_list_iter != one_target_list.end(); ++one_target_list_iter){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm if((*expand_hostname_list_iter) == (*one_target_list_iter)){ // found! foundname = *expand_hostname_list_iter; @@ -441,6 +443,8 @@ bool IsMatchHostname(const char* target, strlst_t& regex_lst, string& foundname) } // compare each host in expand host for(strlst_t::const_iterator one_target_list_iter = one_target_list.begin(); one_target_list_iter != one_target_list.end(); ++one_target_list_iter){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm if(0 == regexec(®ex_obj, one_target_list_iter->c_str(), 0, NULL, 0)){ // match! foundname = (*one_target_list_iter); diff --git a/lib/chmssgnutls.h b/lib/chmssgnutls.h index e84edfb..7fd4568 100644 --- a/lib/chmssgnutls.h +++ b/lib/chmssgnutls.h @@ -36,6 +36,8 @@ typedef struct chm_gnutls_ss_context* ChmSSCtx; // this type is opaque //--------------------------------------------------------- // ChmSecureSock Class for OpenSSL //--------------------------------------------------------- +// cppcheck-suppress unmatchedSuppression +// cppcheck-suppress ctuOneDefinitionRuleViolation class ChmSecureSock { protected: diff --git a/lib/chmssnss.h b/lib/chmssnss.h index 22fb5c5..d832a29 100644 --- a/lib/chmssnss.h +++ b/lib/chmssnss.h @@ -47,6 +47,8 @@ typedef std::list chmpk11list_t; //--------------------------------------------------------- // ChmSecureSock Class for OpenSSL //--------------------------------------------------------- +// cppcheck-suppress unmatchedSuppression +// cppcheck-suppress ctuOneDefinitionRuleViolation class ChmSecureSock { protected: diff --git a/lib/chmssopenssl.cc b/lib/chmssopenssl.cc index 7671d10..2bd57b8 100644 --- a/lib/chmssopenssl.cc +++ b/lib/chmssopenssl.cc @@ -455,6 +455,7 @@ ChmSSCtx ChmSecureSock::MakeSSLContext(const char* server_cert, const char* serv ERR_CHMPRN("Could not make SSL Context."); return NULL; } + // Restrict the protocol according to the setting. if(!ChmSecureSock::SetMinVersion(ctx)){ ERR_CHMPRN("Setting of minimum SSL/TLS version failed."); diff --git a/lib/chmssopenssl.h b/lib/chmssopenssl.h index 1092630..882142b 100644 --- a/lib/chmssopenssl.h +++ b/lib/chmssopenssl.h @@ -37,6 +37,8 @@ typedef SSL_CTX* ChmSSCtx; //--------------------------------------------------------- // ChmSecureSock Class for OpenSSL //--------------------------------------------------------- +// cppcheck-suppress unmatchedSuppression +// cppcheck-suppress ctuOneDefinitionRuleViolation class ChmSecureSock { protected: diff --git a/lib/chmstream.h b/lib/chmstream.h index d9de5ae..67150c4 100644 --- a/lib/chmstream.h +++ b/lib/chmstream.h @@ -80,8 +80,8 @@ class basic_chmstreambuf : public std::basic_streambuf bool receive_sync(void); public: - basic_chmstreambuf(open_mode opmode = std::ios_base::in | std::ios_base::out); // Do not call this - basic_chmstreambuf(ChmCntrl* pchmobj, open_mode opmode = std::ios_base::in | std::ios_base::out); + explicit basic_chmstreambuf(open_mode opmode = std::ios_base::in | std::ios_base::out); // Do not call this + explicit basic_chmstreambuf(ChmCntrl* pchmobj, open_mode opmode = std::ios_base::in | std::ios_base::out); basic_chmstreambuf(ChmCntrl* pchmobj, chmhash_t hash, open_mode opmode = std::ios_base::in | std::ios_base::out); basic_chmstreambuf(ChmCntrl* pchmobj, const std::string& strkey, open_mode opmode = std::ios_base::in | std::ios_base::out); virtual ~basic_chmstreambuf(); @@ -818,10 +818,10 @@ class basic_ichmstream : public std::basic_istream chmstreambuf_type chmstreambuf; protected: - basic_ichmstream(open_mode opmode = std::ios_base::in) : istream_type(), chmstreambuf(opmode | std::ios_base::in) { ios_type::init(&chmstreambuf); } + explicit basic_ichmstream(open_mode opmode = std::ios_base::in) : istream_type(), chmstreambuf(opmode | std::ios_base::in) { ios_type::init(&chmstreambuf); } public: - basic_ichmstream(ChmCntrl* pchmobj, open_mode opmode = std::ios_base::in) : istream_type(), chmstreambuf(pchmobj, opmode | std::ios_base::in) { ios_type::init(&chmstreambuf); } + explicit basic_ichmstream(ChmCntrl* pchmobj, open_mode opmode = std::ios_base::in) : istream_type(), chmstreambuf(pchmobj, opmode | std::ios_base::in) { ios_type::init(&chmstreambuf); } ~basic_ichmstream() { } chmstreambuf_type* rdbuf() const { return const_cast(&chmstreambuf); } @@ -850,10 +850,10 @@ class basic_ochmstream : public std::basic_ostream chmstreambuf_type chmstreambuf; protected: - basic_ochmstream(open_mode opmode = std::ios_base::out) : ostream_type(), chmstreambuf(opmode | std::ios_base::out) { ios_type::init(&chmstreambuf); } + explicit basic_ochmstream(open_mode opmode = std::ios_base::out) : ostream_type(), chmstreambuf(opmode | std::ios_base::out) { ios_type::init(&chmstreambuf); } public: - basic_ochmstream(ChmCntrl* pchmobj, open_mode opmode = std::ios_base::out) : ostream_type(), chmstreambuf(pchmobj, opmode | std::ios_base::out) { ios_type::init(&chmstreambuf); } + explicit basic_ochmstream(ChmCntrl* pchmobj, open_mode opmode = std::ios_base::out) : ostream_type(), chmstreambuf(pchmobj, opmode | std::ios_base::out) { ios_type::init(&chmstreambuf); } basic_ochmstream(ChmCntrl* pchmobj, chmhash_t hash, open_mode opmode = std::ios_base::out) : ostream_type(), chmstreambuf(pchmobj, hash, opmode | std::ios_base::out) { ios_type::init(&chmstreambuf); } basic_ochmstream(ChmCntrl* pchmobj, const std::string& strkey, open_mode opmode = std::ios_base::out) : ostream_type(), chmstreambuf(pchmobj, strkey, opmode | std::ios_base::out) { ios_type::init(&chmstreambuf); } ~basic_ochmstream() { } @@ -884,10 +884,10 @@ class basic_chmstream : public std::basic_iostream chmstreambuf_type chmstreambuf; protected: - basic_chmstream(open_mode opmode = std::ios_base::out | std::ios_base::in) : iostream_type(), chmstreambuf(opmode | std::ios_base::out | std::ios_base::in) { ios_type::init(&chmstreambuf); } + explicit basic_chmstream(open_mode opmode = std::ios_base::out | std::ios_base::in) : iostream_type(), chmstreambuf(opmode | std::ios_base::out | std::ios_base::in) { ios_type::init(&chmstreambuf); } public: - basic_chmstream(ChmCntrl* pchmobj, open_mode opmode = std::ios_base::out | std::ios_base::in) : iostream_type(), chmstreambuf(pchmobj, opmode | std::ios_base::out | std::ios_base::in) { ios_type::init(&chmstreambuf); } + explicit basic_chmstream(ChmCntrl* pchmobj, open_mode opmode = std::ios_base::out | std::ios_base::in) : iostream_type(), chmstreambuf(pchmobj, opmode | std::ios_base::out | std::ios_base::in) { ios_type::init(&chmstreambuf); } basic_chmstream(ChmCntrl* pchmobj, chmhash_t hash, open_mode opmode = std::ios_base::out | std::ios_base::in) : iostream_type(), chmstreambuf(pchmobj, hash, opmode | std::ios_base::out | std::ios_base::in) { ios_type::init(&chmstreambuf); } basic_chmstream(ChmCntrl* pchmobj, const std::string& strkey, open_mode opmode = std::ios_base::out | std::ios_base::in) : iostream_type(), chmstreambuf(pchmobj, strkey, opmode | std::ios_base::out | std::ios_base::in) { ios_type::init(&chmstreambuf); } ~basic_chmstream() { } diff --git a/lib/chmstructure.tcc b/lib/chmstructure.tcc index c84e121..6f26f65 100644 --- a/lib/chmstructure.tcc +++ b/lib/chmstructure.tcc @@ -441,8 +441,8 @@ inline std::string CvtUpdateTimeToString(time_t updatetime) long nsec= 0; ParseUpdateTime(updatetime, sec, nsec); - char buf[128]; - struct tm* tm = localtime(&sec); + char buf[128]; + const struct tm* tm = localtime(&sec); strftime(buf, sizeof(buf), "%Y-%m-%d %Hh %Mm %Ss ", tm); std::string result = std::string(buf) + to_string(nsec / (1000 * 1000)) + std::string("ms ") + to_string((nsec / 1000) % 1000) + std::string("us"); diff --git a/lib/chmthread.cc b/lib/chmthread.cc index 68e831e..55b11e2 100644 --- a/lib/chmthread.cc +++ b/lib/chmthread.cc @@ -450,6 +450,8 @@ bool ChmThread::WaitExitThread(PCHMTHWP_PARAM thread_param) } // check sleeping list for(chmthlist_t::iterator iter = chmthsleeps.begin(); iter != chmthsleeps.end(); ++iter){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm if(thread_param == (*iter)){ chmthsleeps.erase(iter); break; @@ -457,6 +459,8 @@ bool ChmThread::WaitExitThread(PCHMTHWP_PARAM thread_param) } // remove from all list for(chmthlist_t::iterator iter = chmthlist.begin(); iter != chmthlist.end(); ++iter){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm if(thread_param == (*iter)){ chmthlist.erase(iter); break; @@ -466,6 +470,8 @@ bool ChmThread::WaitExitThread(PCHMTHWP_PARAM thread_param) // clear parameter if(free_proc){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownPointerToBool if(!free_proc(thread_param->common_param, thread_param->wp_param)){ MSG_CHMPRN("Failed to free parameter for thread, but continue..."); } diff --git a/lib/chmutil.cc b/lib/chmutil.cc index 223c29f..cf9bc01 100644 --- a/lib/chmutil.cc +++ b/lib/chmutil.cc @@ -45,7 +45,7 @@ string str_rfcdate(time_t date) if(-1 == date){ date = time(NULL); } - char* oldlocale = setlocale(LC_TIME, "C"); + const char* oldlocale = setlocale(LC_TIME, "C"); char buff[128]; strftime(buff, sizeof(buff), "%a, %d %b %Y %T %z", gmtime(&date)); @@ -60,7 +60,7 @@ time_t rfcdate_time(const char* rfcdate) if(CHMEMPTYSTR(rfcdate)){ return 0L; // ... } - char* oldlocale = setlocale(LC_TIME, "C"); + const char* oldlocale = setlocale(LC_TIME, "C"); struct tm tmdate; strptime(rfcdate, "%a, %d %b %Y %T %z", &tmdate); diff --git a/lib/chmutil.h b/lib/chmutil.h index 28dfa3b..17483a3 100644 --- a/lib/chmutil.h +++ b/lib/chmutil.h @@ -66,7 +66,7 @@ struct merge_map typedef typename std::map merge_map_t; typedef typename std::map::const_iterator merge_map_iterator; - merge_map(merge_map_t& map1, merge_map_t& map2) + merge_map(merge_map_t& map1, const merge_map_t& map2) { for(merge_map_iterator iter = map2.begin(); iter != map2.end(); ++iter){ map1[iter->first] = iter->second; @@ -203,7 +203,7 @@ template inline void FIN_MATE_TIMESPEC(T* ptr) SUB_TIMESPEC(&ts, ptr); COPY_TIMESPEC(ptr, &ts); } -template inline void FIN_MATE_TIMESPEC2(T* start, T* fin, T* elapsed) +template inline void FIN_MATE_TIMESPEC2(const T* start, T* fin, T* elapsed) { if(!RT_TIMESPEC(fin)){ INIT_TIMESPEC(fin); diff --git a/src/chmmain.cc b/src/chmmain.cc index 5b99ba5..42dffb3 100644 --- a/src/chmmain.cc +++ b/src/chmmain.cc @@ -164,7 +164,7 @@ int main(int argc, char** argv) } } - ChmOpts opts((argc - 1), &argv[1]); + ChmOpts opts((argc - 1), const_cast(&argv[1])); // help if(opts.Find(OPT_HELP1) || opts.Find(OPT_HELP2)){ diff --git a/tests/chmpxbench.cc b/tests/chmpxbench.cc index 1a81873..f5378bf 100644 --- a/tests/chmpxbench.cc +++ b/tests/chmpxbench.cc @@ -162,7 +162,7 @@ static bool SetStringBytes(string& str, size_t totallength, char ch) return true; } -inline string to_short(string& base) +inline string to_short(const string& base) { return base.substr(0, MINIMUM_DATA_LENGTH); } @@ -385,6 +385,9 @@ static int OpenBenchFile(const string& filepath, size_t& totalsize, bool is_crea // truncate & clean up if(0 != ftruncate(fd, totalsize)){ ERR("Could not truncate file(%s) to %zu, errno = %d", filepath.c_str(), totalsize, errno); + + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable CHM_CLOSE(fd); return -1; } @@ -394,6 +397,9 @@ static int OpenBenchFile(const string& filepath, size_t& totalsize, bool is_crea onewrote = min(static_cast(sizeof(unsigned char) * 1024), (totalsize - static_cast(wrote))); if(-1 == (onewrote = pwrite(fd, szBuff, static_cast(onewrote), static_cast(wrote)))){ ERR("Failed to write initializing file(%s), errno = %d", filepath.c_str(), errno); + + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable CHM_CLOSE(fd); return -1; } @@ -802,6 +808,9 @@ static int RunChild(string cntlfile) if(pexeccntl->is_exit){ ERR("Exit process ASSAP."); munmap(pShmBase, totalsize); + + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable CHM_CLOSE(cntlfd); return EXIT_FAILURE; } @@ -817,6 +826,9 @@ static int RunChild(string cntlfile) if(!pmycntl){ ERR("Could not find my procid in PCHLDCNTL."); munmap(pShmBase, totalsize); + + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable CHM_CLOSE(cntlfd); return EXIT_FAILURE; } @@ -833,6 +845,9 @@ static int RunChild(string cntlfile) ERR("Could not initialize internal object/data/etc."); CHM_Delete(pCntlObj); munmap(pShmBase, totalsize); + + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable CHM_CLOSE(cntlfd); return EXIT_FAILURE; } @@ -966,7 +981,7 @@ static void PrintResult(const PEXECCNTL pexeccntl, const PCHLDCNTL pchldcntl, co int main(int argc, char** argv) { // parse parameters - ChmOpts opts((argc - 1), &argv[1]); + ChmOpts opts((argc - 1), const_cast(&argv[1])); // help if(opts.Find("h") || opts.Find("help")){ @@ -1124,6 +1139,9 @@ int main(int argc, char** argv) // cleanup munmap(pShmBase, totalsize); + + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable CHM_CLOSE(cntlfd); unlink(cntlfile.c_str()); diff --git a/tests/chmpxconftest.cc b/tests/chmpxconftest.cc index 8de34cf..9ebb6f7 100644 --- a/tests/chmpxconftest.cc +++ b/tests/chmpxconftest.cc @@ -45,7 +45,7 @@ using namespace std; //--------------------------------------------------------- // Parse parameters // -static void Help(char* progname) +static void Help(const char* progname) { printf("Usage: %s [options]\n", progname ? progname : "program"); printf("Option -conf [file name] Configuration file( .ini / .json / .yaml ) path\n"); @@ -281,11 +281,11 @@ void print_initial_datas(void) //--------------------------------------------------------- int main(int argc, char** argv) { - ChmOpts opts((argc - 1), &argv[1]); + ChmOpts opts((argc - 1), const_cast(&argv[1])); // help if(opts.Find("h") || opts.Find("help")){ - char* pprgname = basename(argv[0]); + const char* pprgname = basename(argv[0]); Help(pprgname); exit(EXIT_SUCCESS); } diff --git a/tests/chmpxlinetool.cc b/tests/chmpxlinetool.cc index 6a503e1..16b153b 100644 --- a/tests/chmpxlinetool.cc +++ b/tests/chmpxlinetool.cc @@ -140,6 +140,8 @@ static inline bool merge_chostinfolist(chostinfolist_t& baselist, const chostinf bool found; found = false; for(chostinfolist_t::iterator biter = baselist.begin(); biter != baselist.end(); ++biter){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm if(biter->hostname == aiter->hostname){ found = true; if(!biter->confirmed && aiter->confirmed){ @@ -162,6 +164,8 @@ static inline bool add_chostinfolist(chostinfolist_t& baselist, const string& ho { bool found = false; for(chostinfolist_t::iterator biter = baselist.begin(); biter != baselist.end(); ++biter){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm if(biter->hostname == hostname){ found = true; if(!biter->confirmed && confirmed){ @@ -283,6 +287,8 @@ bool HostnameMap::MakeHostnamesMap(const strlst_t& hostnames, bool confirmed) if(plist){ bool found = false; for(hpiter = existedhostlist.begin(); hpiter != existedhostlist.end(); ++hpiter){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm if(plist == (*hpiter)){ found = true; break; @@ -381,7 +387,7 @@ bool HostnameMap::GetHostnames(const char* target, chostinfolist_t& chostinfolis return false; } // search cache - chostinfolist_t* pchostinfolist = HostnameMap::FindHostnamesPtr(target); + const chostinfolist_t* pchostinfolist = HostnameMap::FindHostnamesPtr(target); if(pchostinfolist){ chostinfolist = *pchostinfolist; }else{ @@ -653,13 +659,14 @@ bool NodeCtrlInfo::GetMaximumChmpxidList(chmpxidlist_t& chmpxidlist) const strlst_t::iterator siter; strlst_t hostnames; - chmpxid_t tmpchmpxid; if(HostnameMap::GetHostnames(hostname.c_str(), hostnames) && !hostnames.empty()){ for(siter = hostnames.begin(); siter != hostnames.end(); ++siter){ - tmpchmpxid = MakeChmpxId(NodeCtrlInfo::groupName.c_str(), NodeCtrlInfo::chmpxidType, siter->c_str(), ctrlport, cuk.c_str(), ctlendpoints.c_str(), custom_seed.c_str()); + chmpxid_t tmpchmpxid = MakeChmpxId(NodeCtrlInfo::groupName.c_str(), NodeCtrlInfo::chmpxidType, siter->c_str(), ctrlport, cuk.c_str(), ctlendpoints.c_str(), custom_seed.c_str()); if(CHM_INVALID_CHMPXID != tmpchmpxid){ bool found = false; for(chmpxidlist_t::const_iterator iter = chmpxidlist.begin(); iter != chmpxidlist.end(); ++iter){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm if(*iter == tmpchmpxid){ found = true; break; @@ -689,6 +696,8 @@ int NodeCtrlInfo::compare(const NodeCtrlInfo& other) const // compare chmpxid for(chmpxidlist_t::const_iterator biter = baselist.begin(); biter != baselist.end(); ++biter){ for(chmpxidlist_t::const_iterator oiter = otherlist.begin(); oiter != otherlist.end(); ++oiter){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm if((*biter) == (*oiter)){ // found return 0; @@ -727,6 +736,8 @@ bool NodeCtrlInfo::IsConfirmHostname(void) const return false; } for(strlst_t::iterator siter = hostnames.begin(); siter != hostnames.end(); ++siter){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm if((*siter) == hostname){ // found hostname in confirm hostname list return true; @@ -1008,6 +1019,8 @@ static size_t get_chmpx_nodes_count(const nodectrllist_t& nodes, bool is_server) size_t rescnt = 0; for(nodectrllist_t::const_iterator iter = nodes.begin(); iter != nodes.end(); ++iter){ if(is_server == iter->IsServerNode()){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm ++rescnt; } } @@ -1066,6 +1079,8 @@ static bool find_chmpx_node_by_hostname(const nodectrllist_t& nodes, const strin true); // do not care this value, because compare does not look this. for(nodectrllist_t::const_iterator iter = nodes.begin(); iter != nodes.end(); ++iter){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress useStlAlgorithm if(0 == iter->compare(node)){ // found node = *iter; @@ -2397,6 +2412,8 @@ static bool ReceiveControlSocket(int sock, string& strReceive) ssize_t pos = 0; if(NULL == (pTotalBuff = reinterpret_cast(malloc(totallength)))){ ERR("Could not allocate memory."); + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable CHM_CLOSESOCK(sock); return false; } @@ -2415,12 +2432,16 @@ static bool ReceiveControlSocket(int sock, string& strReceive) }else if(EBADF == errno || ECONNREFUSED == errno || ENOTCONN == errno || ENOTSOCK == errno){ WAN("There are no received data on sock(%d), errno=%d(EBADF or ECONNREFUSED or ENOTCONN or ENOTSOCK).", sock, errno); + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable CHM_CLOSESOCK(sock); CHM_Free(pTotalBuff); return false; }else{ WAN("Failed to receive from sock(%d), errno=%d, then closing this socket.", sock, errno); + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable CHM_CLOSESOCK(sock); CHM_Free(pTotalBuff); return false; @@ -2439,6 +2460,8 @@ static bool ReceiveControlSocket(int sock, string& strReceive) char* pTmp; if(NULL == (pTmp = reinterpret_cast(realloc(pTotalBuff, totallength + RECEIVE_LENGTH)))){ ERR("Could not allocate memory."); + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable CHM_CLOSESOCK(sock); CHM_Free(pTotalBuff); return false; @@ -2449,6 +2472,8 @@ static bool ReceiveControlSocket(int sock, string& strReceive) } } // close sock at first + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable CHM_CLOSESOCK(sock); if(0 < pos && '\0' != pTotalBuff[pos - 1]){ @@ -2456,6 +2481,9 @@ static bool ReceiveControlSocket(int sock, string& strReceive) char* pTmp; if(NULL == (pTmp = reinterpret_cast(realloc(pTotalBuff, static_cast(pos + 1))))){ ERR("Could not allocate memory."); + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress uselessAssignmentArg + // cppcheck-suppress unreadVariable CHM_CLOSESOCK(sock); CHM_Free(pTotalBuff); return false; @@ -2561,6 +2589,8 @@ static int OneConnectControlPort(const char* hostname, short port) // connect if(-1 == connect(sockfd, ptmpaddrinfo->ai_addr, ptmpaddrinfo->ai_addrlen)){ MSG("Failed to connect for %s:%d by errno=%d, but continue to make next addrinfo...", hostname, port, errno); + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable CHM_CLOSESOCK(sockfd); continue; } @@ -2632,6 +2662,8 @@ static bool SendCommandToControlPort(const char* hostname, short ctrlport, const if(!SendControlSocket(ctlsock, pCommand, is_closed)){ WAN("Could not send to %s:%d(sock:%d).", hostname, ctrlport, ctlsock); if(!is_closed){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable CHM_CLOSESOCK(ctlsock); } return false; @@ -3181,7 +3213,7 @@ static string ParseChmpxListFromDumpResult(nodectrllist_t& nodes, const string& return strInput; } -static bool AddNodesFromDumpResult(nodectrllist_t& nodes, string& strDump) +static bool AddNodesFromDumpResult(nodectrllist_t& nodes, const string& strDump) { string strParsed; string::size_type pos; @@ -6214,7 +6246,7 @@ static bool LoopCommand(ConsoleInput& InputIF, params_t& params, bool& is_exit) CommandList.push_back(strLine); } - if(0 == CommandList.size()){ + if(CommandList.empty()){ return true; } @@ -6271,16 +6303,22 @@ static bool SaveCommand(const ConsoleInput& InputIF, params_t& params) for(pHistory = iter->c_str(), wrote_byte = 0, one_wrote_byte = 0L; wrote_byte < iter->length(); wrote_byte += one_wrote_byte){ if(-1 == (one_wrote_byte = write(fd, &pHistory[wrote_byte], (iter->length() - wrote_byte)))){ ERR("Failed writing history to file(%s). errno(%d)", params[0].c_str(), errno); + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable CHM_CLOSE(fd); return true; // for continue } } if(-1 == write(fd, "\n", 1)){ ERR("Failed writing history to file(%s). errno(%d)", params[0].c_str(), errno); + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable CHM_CLOSE(fd); return true; // for continue } } + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable CHM_CLOSE(fd); return true; } @@ -6311,6 +6349,8 @@ static bool LoadCommand(ConsoleInput& InputIF, params_t& params, bool& is_exit) } CommandList.push_back(CommandLine); } + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable CHM_CLOSE(fd); // run @@ -6812,7 +6852,7 @@ int main(int argc, char** argv) } // -status if(opts.end() != opts.find("-status")){ - if(0 < StartupLoopCommand.size()){ + if(!StartupLoopCommand.empty()){ ERR("Option \"-run\" and \"-check\" and \"-status\" are exclusive specifications."); exit(EXIT_FAILURE); } @@ -6854,7 +6894,7 @@ int main(int argc, char** argv) // // check conflict option // - if(0 < StartupLoopCommand.size() && !CommandFile.empty()){ + if(!StartupLoopCommand.empty() && !CommandFile.empty()){ ERR("Option \"-run\" and \"-check\" and \"-status\" are exclusive specifications."); exit(EXIT_FAILURE); } @@ -6918,7 +6958,7 @@ int main(int argc, char** argv) } CommandFile.clear(); - }else if(0 < StartupLoopCommand.size()){ + }else if(!StartupLoopCommand.empty()){ // command check or status at starting bool is_exit = false; if(!ConsecutiveCommands(InputIF, StartupLoopCommand, nTmpIntervalSec, 0, false, is_exit) || is_exit){ @@ -6926,7 +6966,6 @@ int main(int argc, char** argv) } StartupLoopCommand.clear(); - // cppcheck-suppress knownConditionTrueFalse }else if(IsWelcomMsg){ // print message PRN("-------------------------------------------------------"); diff --git a/tests/chmpxstatus.cc b/tests/chmpxstatus.cc index 6252188..f6861c0 100644 --- a/tests/chmpxstatus.cc +++ b/tests/chmpxstatus.cc @@ -562,7 +562,7 @@ static bool StatusWait(ChmCntrl* pchmobj, chmpxsts_t targetsts, time_t timeout) int main(int argc, char** argv) { // parse parameters - ChmOpts opts((argc - 1), &argv[1]); + ChmOpts opts((argc - 1), const_cast(&argv[1])); // help if(opts.Find("h") || opts.Find("help")){ diff --git a/tests/chmpxstreamtest.cc b/tests/chmpxstreamtest.cc index 466ce3a..b8081e2 100644 --- a/tests/chmpxstreamtest.cc +++ b/tests/chmpxstreamtest.cc @@ -578,7 +578,7 @@ static bool TestSlaveSide(ChmCntrl& chmobj) // -d [debug level] "ERR" / "WAN" / "INF" / "DUMP" // -h display help // -static void Help(char* progname) +static void Help(const char* progname) { printf("Usage: %s [options]\n", progname ? progname : "program"); printf("Option -s|-c Specify server side or slave side process.\n"); @@ -593,12 +593,12 @@ static void Help(char* progname) //--------------------------------------------------------- int main(int argc, char** argv) { - ChmOpts opts((argc - 1), &argv[1]); + ChmOpts opts((argc - 1), const_cast(&argv[1])); ChmCntrl chmobj; // help if(opts.Find("h") || opts.Find("help")){ - char* pprgname = basename(argv[0]); + const char* pprgname = basename(argv[0]); Help(pprgname); exit(EXIT_SUCCESS); }