From f56664390b6c49ee351163791a70b65afc07092a Mon Sep 17 00:00:00 2001 From: Takeshi Nakatani Date: Mon, 11 Mar 2024 13:20:49 +0900 Subject: [PATCH] Changed support OS and Fixed about cppcheck, etc --- .github/workflows/ci.yml | 25 ++++--- .github/workflows/ostypevars.sh | 24 +++++-- Makefile.am | 38 +++++++--- buildutils/control.in | 6 +- buildutils/k2hdkc.spec.in | 8 +-- configure.ac | 6 +- lib/k2hdkc.cc | 2 +- lib/k2hdkccombase.cc | 2 + src/k2hdkcconfparser.cc | 4 +- tests/k2hdkclinetool.cc | 119 +++++++++++++++++++++++++++----- 10 files changed, 181 insertions(+), 53 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8dbffc4..fae6fb5 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 c7e636c..065cde2 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 chmpx-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 chmpx-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 chmpx-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 chmpx-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 chmpx-dev openssl-dev" diff --git a/Makefile.am b/Makefile.am index ac5af5c..a696cfe 100644 --- a/Makefile.am +++ b/Makefile.am @@ -28,23 +28,36 @@ 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] +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 = +# [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_GT207_VER = 2007 +CPPCHECK_GT207_ADD_OPT = --suppress=ctuOneDefinitionRuleViolation +CPPCHECK_GE211_VER = 2011 +CPPCHECK_GE211_ADD_OPT = --check-level=exhaustive \ + --suppress=missingIncludeSystem + 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"; \ @@ -52,7 +65,13 @@ 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_GT207_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_GE211_VER); then \ + $(CPPCHECK_CMD) $(CPPCHECK_BASE_OPT) $(CPPCHECK_DEFINE_OPT) $(CPPCHECK_INCDIR_OPT) $(CPPCHECK_ENABLE_OPT) $(CPPCHECK_IGNORE_OPT) $(CPPCHECK_GT207_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_GT207_ADD_OPT) $(CPPCHECK_GE211_ADD_OPT) --cppcheck-build-dir=$(CPPCHECK_BUILD_DIR) $(CPPCHECK_TARGET); \ + fi; \ rm -rf $(CPPCHECK_BUILD_DIR); \ fi; \ else \ @@ -76,16 +95,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/control.in b/buildutils/control.in index 1621e82..08cd757 100644 --- a/buildutils/control.in +++ b/buildutils/control.in @@ -2,7 +2,7 @@ Source: @PACKAGE_NAME@ Section: database Priority: optional Maintainer: @DEV_NAME@ <@DEV_EMAIL@> -Build-Depends: @DEBHELPER_DEP@, k2hash-dev (>= 1.0.92), chmpx-dev (>= 1.0.104), libfullock-dev (>= 1.0.57), libyaml-dev, gnutls-dev +Build-Depends: @DEBHELPER_DEP@, k2hash-dev (>= 1.0.93), chmpx-dev (>= 1.0.105), 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), chmpx-dev (>= 1.0.104), libfullock-dev (>= 1.0.57), libyaml-dev, gnutls-dev +Depends: ${misc:Depends}, @PACKAGE_NAME@ (= ${binary:Version}), k2hash-dev (>= 1.0.93), chmpx-dev (>= 1.0.105), 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: database Architecture: amd64 -Depends: ${shlibs:Depends}, ${misc:Depends}, init-system-helpers (>= 1.14), k2hash (>= 1.0.92), chmpx (>= 1.0.104), libfullock (>= 1.0.57) +Depends: ${shlibs:Depends}, ${misc:Depends}, init-system-helpers (>= 1.14), k2hash (>= 1.0.93), chmpx (>= 1.0.105), libfullock (>= 1.0.59) Description: @SHORTDESC@ @DEBLONGDESC@ diff --git a/buildutils/k2hdkc.spec.in b/buildutils/k2hdkc.spec.in index ea31de9..ed8889e 100644 --- a/buildutils/k2hdkc.spec.in +++ b/buildutils/k2hdkc.spec.in @@ -53,11 +53,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: libfullock%{?_isa} >= 1.0.57, k2hash%{?_isa} >= 1.0.92, chmpx%{?_isa} >= 1.0.104 +Requires: libfullock%{?_isa} >= 1.0.59, k2hash%{?_isa} >= 1.0.93, chmpx%{?_isa} >= 1.0.105 %if 0%{?rhel} == 6 -BuildRequires: git-core gcc-c++ make libtool libfullock-devel >= 1.0.57, k2hash-devel >= 1.0.92, chmpx-devel >= 1.0.104, libyaml-devel, nss-devel +BuildRequires: git-core gcc-c++ make libtool libfullock-devel >= 1.0.59, k2hash-devel >= 1.0.93, chmpx-devel >= 1.0.105, libyaml-devel, nss-devel %else -BuildRequires: systemd git-core gcc-c++ make libtool libfullock-devel >= 1.0.57, k2hash-devel >= 1.0.92, chmpx-devel >= 1.0.104, libyaml-devel, nss-devel +BuildRequires: systemd git-core gcc-c++ make libtool libfullock-devel >= 1.0.59, k2hash-devel >= 1.0.93, chmpx-devel >= 1.0.105, libyaml-devel, nss-devel %endif %description @@ -126,7 +126,7 @@ rm -rf %{buildroot} # %package devel Summary: @SHORTDESC@ (development) -Requires: %{name}%{?_isa} = %{version}-%{release}, libfullock-devel%{?_isa} >= 1.0.57, k2hash-devel%{?_isa} >= 1.0.92, chmpx-devel%{?_isa} >= 1.0.104, libyaml-devel, nss-devel +Requires: %{name}%{?_isa} = %{version}-%{release}, libfullock-devel%{?_isa} >= 1.0.59, k2hash-devel%{?_isa} >= 1.0.93, chmpx-devel%{?_isa} >= 1.0.105, libyaml-devel, nss-devel %description devel Development package for building with @PACKAGE_NAME@ shared library. diff --git a/configure.ac b/configure.ac index a0b3ba2..bd22e52 100644 --- a/configure.ac +++ b/configure.ac @@ -154,9 +154,9 @@ 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([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.92], [], [AC_MSG_ERROR(not found k2hash package)])]) -AS_IF([test ${check_depend_libs} = 1], [PKG_CHECK_MODULES([chmpx], [libchmpx >= 1.0.104], [], [AC_MSG_ERROR(not found chmpx package)])]) +AS_IF([test ${check_depend_libs} = 1], [PKG_CHECK_MODULES([fullock], [libfullock >= 1.0.59], [], [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([chmpx], [libchmpx >= 1.0.105], [], [AC_MSG_ERROR(not found chmpx package)])]) # # CFLAGS/CXXFLAGS diff --git a/lib/k2hdkc.cc b/lib/k2hdkc.cc index 83a69d3..3a4abea 100644 --- a/lib/k2hdkc.cc +++ b/lib/k2hdkc.cc @@ -141,7 +141,7 @@ dkcres_type_t k2hdkc_get_res_code(k2hdkc_chmpx_h handle) ERR_DKCPRN("Parameter handle is invalid."); return DKC_NORESTYPE; } - K2hdkcSlave* pSlave = reinterpret_cast(handle); + const K2hdkcSlave* pSlave = reinterpret_cast(handle); return pSlave->GetResponseCode(); } diff --git a/lib/k2hdkccombase.cc b/lib/k2hdkccombase.cc index 96f5b01..82284d2 100644 --- a/lib/k2hdkccombase.cc +++ b/lib/k2hdkccombase.cc @@ -977,6 +977,8 @@ bool K2hdkcCommand::CommandSending(void) TriggerResponse = false; // set callback + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownPointerToBool if(!K2hdkcCommand::WaitFp(pSendComAll->com_head.comnumber, this, K2hdkcCommand::pWaitFpParam)){ // cppcheck-suppress literalWithCharPtrCompare ERR_DKCPRN("Failed to set receive waiting callback for type(%s).", STR_DKCCOM_TYPE(pSendComAll->com_head.comtype)); diff --git a/src/k2hdkcconfparser.cc b/src/k2hdkcconfparser.cc index 9e70cf4..2e64db4 100644 --- a/src/k2hdkcconfparser.cc +++ b/src/k2hdkcconfparser.cc @@ -1225,9 +1225,7 @@ bool K2hdkcConfig::InitializeK2hash(K2HShm& k2hash) const ERR_DKCPRN("Failed to set k2hash about encrypt pass phrase."); return false; } - if(set_default){ - set_default = false; - } + set_default = false; } } MSG_DKCPRN("Succeed: set attributes"); diff --git a/tests/k2hdkclinetool.cc b/tests/k2hdkclinetool.cc index c6b3000..8970769 100644 --- a/tests/k2hdkclinetool.cc +++ b/tests/k2hdkclinetool.cc @@ -1139,16 +1139,22 @@ static bool ReadContentsFromFile(const char* pFile, off_t offset, size_t reqleng struct stat st; if(-1 == fstat(fd, &st)){ ERR("Could not get stat for file(%s) by errno(%d)", pFile, errno); + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable DKC_CLOSE(fd); return false; } if(st.st_size <= 0){ ERR("file(%s) does not have any contents", pFile); + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable DKC_CLOSE(fd); return false; } if(static_cast(st.st_size) <= offset){ ERR("file(%s) does not have any contents after %zd offset", pFile, offset); + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable DKC_CLOSE(fd); return false; } @@ -1159,6 +1165,8 @@ static bool ReadContentsFromFile(const char* pFile, off_t offset, size_t reqleng } if(NULL == ((*ppval) = reinterpret_cast(malloc(reqlength)))){ ERR("Could not allocate memory."); + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable DKC_CLOSE(fd); return false; } @@ -1169,6 +1177,8 @@ static bool ReadContentsFromFile(const char* pFile, off_t offset, size_t reqleng for(read_cnt = 0L, one_read = 0L; static_cast(read_cnt) < reqlength; read_cnt += one_read){ if(-1 == (one_read = pread(fd, &((*ppval)[read_cnt]), (reqlength - static_cast(read_cnt)), static_cast(offset + read_cnt)))){ ERR("Failed to read from fd(%d : %jd : %zu) by errno(%d)", fd, static_cast(offset + read_cnt), reqlength - static_cast(read_cnt), errno); + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable DKC_CLOSE(fd); DKC_FREE(*ppval); vallength = 0UL; @@ -1180,6 +1190,8 @@ static bool ReadContentsFromFile(const char* pFile, off_t offset, size_t reqleng } if(read_cnt <= 0){ ERR("Could not read any byte from file(%s), it should be %zu byte", pFile, reqlength); + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable DKC_CLOSE(fd); DKC_FREE(*ppval); vallength = 0UL; @@ -1189,6 +1201,9 @@ static bool ReadContentsFromFile(const char* pFile, off_t offset, size_t reqleng WAN("Read only %zd byte from file(%s), it should be %zu byte", read_cnt, pFile, reqlength); } vallength = static_cast(read_cnt); + + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable DKC_CLOSE(fd); return true; @@ -1214,6 +1229,8 @@ static bool AppendContentsToFile(const char* pFile, const unsigned char* pval, s for(ssize_t write_cnt = 0L, one_write = 0L; static_cast(write_cnt) < vallength; write_cnt += one_write){ if(-1 == (one_write = write(fd, &(pval[write_cnt]), (vallength - static_cast(write_cnt))))){ ERR("Failed to write to fd(%d:%zd:%zu), errno = %d", fd, write_cnt, vallength - static_cast(write_cnt), errno); + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable DKC_CLOSE(fd); return false; } @@ -3372,7 +3389,7 @@ static bool QueuePopCommand(k2hdkc_chmpx_h chmpxhandle, const unsigned char* pNa if(PassPhrase.empty()){ result = k2hdkc_full_q_pop(strConfig.c_str(), CntlPort, (strCuk.empty() ? NULL : strCuk.c_str()), isAutoRejoin, isNoGiveupRejoin, pName, NameLen, is_Fifo, &pval, &vallength); }else{ - result = k2hdkc_full_q_pop_wp(strConfig.c_str(), CntlPort, (strCuk.empty() ? NULL : strCuk.c_str()), isAutoRejoin, isNoGiveupRejoin, pName, NameLen, is_Fifo, (PassPhrase.empty() ? NULL : PassPhrase.c_str()), &pval, &vallength); + result = k2hdkc_full_q_pop_wp(strConfig.c_str(), CntlPort, (strCuk.empty() ? NULL : strCuk.c_str()), isAutoRejoin, isNoGiveupRejoin, pName, NameLen, is_Fifo, PassPhrase.c_str(), &pval, &vallength); } rescode = k2hdkc_get_lastres_code(); @@ -3400,7 +3417,7 @@ static bool QueuePopCommand(k2hdkc_chmpx_h chmpxhandle, const unsigned char* pNa if(PassPhrase.empty()){ result = k2hdkc_pm_q_pop(chmpxhandle, pName, NameLen, is_Fifo, &pval, &vallength); }else{ - result = k2hdkc_pm_q_pop_wp(chmpxhandle, pName, NameLen, is_Fifo, (PassPhrase.empty() ? NULL : PassPhrase.c_str()), &pval, &vallength); + result = k2hdkc_pm_q_pop_wp(chmpxhandle, pName, NameLen, is_Fifo, PassPhrase.c_str(), &pval, &vallength); } rescode = k2hdkc_get_res_code(chmpxhandle); @@ -3490,7 +3507,7 @@ static bool QueueRemoveCommand(k2hdkc_chmpx_h chmpxhandle, const unsigned char* if(PassPhrase.empty()){ result = k2hdkc_full_q_remove(strConfig.c_str(), CntlPort, (strCuk.empty() ? NULL : strCuk.c_str()), isAutoRejoin, isNoGiveupRejoin, pName, NameLen, RmCount, is_Fifo); }else{ - result = k2hdkc_full_q_remove_wp(strConfig.c_str(), CntlPort, (strCuk.empty() ? NULL : strCuk.c_str()), isAutoRejoin, isNoGiveupRejoin, pName, NameLen, RmCount, is_Fifo, (PassPhrase.empty() ? NULL : PassPhrase.c_str())); + result = k2hdkc_full_q_remove_wp(strConfig.c_str(), CntlPort, (strCuk.empty() ? NULL : strCuk.c_str()), isAutoRejoin, isNoGiveupRejoin, pName, NameLen, RmCount, is_Fifo, PassPhrase.c_str()); } rescode = k2hdkc_get_lastres_code(); @@ -3512,7 +3529,7 @@ static bool QueueRemoveCommand(k2hdkc_chmpx_h chmpxhandle, const unsigned char* if(PassPhrase.empty()){ result = k2hdkc_pm_q_remove(chmpxhandle, pName, NameLen, RmCount, is_Fifo); }else{ - result = k2hdkc_pm_q_remove_wp(chmpxhandle, pName, NameLen, RmCount, is_Fifo, (PassPhrase.empty() ? NULL : PassPhrase.c_str())); + result = k2hdkc_pm_q_remove_wp(chmpxhandle, pName, NameLen, RmCount, is_Fifo, PassPhrase.c_str()); } rescode = k2hdkc_get_res_code(chmpxhandle); @@ -3712,7 +3729,7 @@ static bool KeyQueuePopCommand(k2hdkc_chmpx_h chmpxhandle, const unsigned char* if(PassPhrase.empty()){ result = k2hdkc_full_keyq_pop(strConfig.c_str(), CntlPort, (strCuk.empty() ? NULL : strCuk.c_str()), isAutoRejoin, isNoGiveupRejoin, pName, NameLen, is_Fifo, &pkey, &keylength, &pval, &vallength); }else{ - result = k2hdkc_full_keyq_pop_wp(strConfig.c_str(), CntlPort, (strCuk.empty() ? NULL : strCuk.c_str()), isAutoRejoin, isNoGiveupRejoin, pName, NameLen, is_Fifo, (PassPhrase.empty() ? NULL : PassPhrase.c_str()), &pkey, &keylength, &pval, &vallength); + result = k2hdkc_full_keyq_pop_wp(strConfig.c_str(), CntlPort, (strCuk.empty() ? NULL : strCuk.c_str()), isAutoRejoin, isNoGiveupRejoin, pName, NameLen, is_Fifo, PassPhrase.c_str(), &pkey, &keylength, &pval, &vallength); } rescode = k2hdkc_get_lastres_code(); @@ -3747,7 +3764,7 @@ static bool KeyQueuePopCommand(k2hdkc_chmpx_h chmpxhandle, const unsigned char* if(PassPhrase.empty()){ result = k2hdkc_pm_keyq_pop(chmpxhandle, pName, NameLen, is_Fifo, &pkey, &keylength, &pval, &vallength); }else{ - result = k2hdkc_pm_keyq_pop_wp(chmpxhandle, pName, NameLen, is_Fifo, (PassPhrase.empty() ? NULL : PassPhrase.c_str()), &pkey, &keylength, &pval, &vallength); + result = k2hdkc_pm_keyq_pop_wp(chmpxhandle, pName, NameLen, is_Fifo, PassPhrase.c_str(), &pkey, &keylength, &pval, &vallength); } rescode = k2hdkc_get_res_code(chmpxhandle); @@ -3847,7 +3864,7 @@ static bool KeyQueueRemoveCommand(k2hdkc_chmpx_h chmpxhandle, const unsigned cha if(PassPhrase.empty()){ result = k2hdkc_full_keyq_remove(strConfig.c_str(), CntlPort, (strCuk.empty() ? NULL : strCuk.c_str()), isAutoRejoin, isNoGiveupRejoin, pName, NameLen, RmCount, is_Fifo); }else{ - result = k2hdkc_full_keyq_remove_wp(strConfig.c_str(), CntlPort, (strCuk.empty() ? NULL : strCuk.c_str()), isAutoRejoin, isNoGiveupRejoin, pName, NameLen, RmCount, is_Fifo, (PassPhrase.empty() ? NULL : PassPhrase.c_str())); + result = k2hdkc_full_keyq_remove_wp(strConfig.c_str(), CntlPort, (strCuk.empty() ? NULL : strCuk.c_str()), isAutoRejoin, isNoGiveupRejoin, pName, NameLen, RmCount, is_Fifo, PassPhrase.c_str()); } rescode = k2hdkc_get_lastres_code(); @@ -3869,7 +3886,7 @@ static bool KeyQueueRemoveCommand(k2hdkc_chmpx_h chmpxhandle, const unsigned cha if(PassPhrase.empty()){ result = k2hdkc_pm_keyq_remove(chmpxhandle, pName, NameLen, RmCount, is_Fifo); }else{ - result = k2hdkc_pm_keyq_remove_wp(chmpxhandle, pName, NameLen, RmCount, is_Fifo, (PassPhrase.empty() ? NULL : PassPhrase.c_str())); + result = k2hdkc_pm_keyq_remove_wp(chmpxhandle, pName, NameLen, RmCount, is_Fifo, PassPhrase.c_str()); } rescode = k2hdkc_get_res_code(chmpxhandle); @@ -4143,13 +4160,13 @@ static bool CasGetCommand(k2hdkc_chmpx_h chmpxhandle, CASTYPE type, params_t& pa } }else{ if(CAS_TYPE_8 == type){ - result = k2hdkc_full_cas8_get_wa(strConfig.c_str(), CntlPort, (strCuk.empty() ? NULL : strCuk.c_str()), isAutoRejoin, isNoGiveupRejoin, reinterpret_cast(strKey.c_str()), strKey.length() + 1, (PassPhrase.empty() ? NULL : PassPhrase.c_str()), &val8); + result = k2hdkc_full_cas8_get_wa(strConfig.c_str(), CntlPort, (strCuk.empty() ? NULL : strCuk.c_str()), isAutoRejoin, isNoGiveupRejoin, reinterpret_cast(strKey.c_str()), strKey.length() + 1, PassPhrase.c_str(), &val8); }else if(CAS_TYPE_16 == type){ - result = k2hdkc_full_cas16_get_wa(strConfig.c_str(), CntlPort, (strCuk.empty() ? NULL : strCuk.c_str()), isAutoRejoin, isNoGiveupRejoin, reinterpret_cast(strKey.c_str()), strKey.length() + 1, (PassPhrase.empty() ? NULL : PassPhrase.c_str()), &val16); + result = k2hdkc_full_cas16_get_wa(strConfig.c_str(), CntlPort, (strCuk.empty() ? NULL : strCuk.c_str()), isAutoRejoin, isNoGiveupRejoin, reinterpret_cast(strKey.c_str()), strKey.length() + 1, PassPhrase.c_str(), &val16); }else if(CAS_TYPE_32 == type){ - result = k2hdkc_full_cas32_get_wa(strConfig.c_str(), CntlPort, (strCuk.empty() ? NULL : strCuk.c_str()), isAutoRejoin, isNoGiveupRejoin, reinterpret_cast(strKey.c_str()), strKey.length() + 1, (PassPhrase.empty() ? NULL : PassPhrase.c_str()), &val32); + result = k2hdkc_full_cas32_get_wa(strConfig.c_str(), CntlPort, (strCuk.empty() ? NULL : strCuk.c_str()), isAutoRejoin, isNoGiveupRejoin, reinterpret_cast(strKey.c_str()), strKey.length() + 1, PassPhrase.c_str(), &val32); }else{ // CAS_TYPE_64 == type - result = k2hdkc_full_cas64_get_wa(strConfig.c_str(), CntlPort, (strCuk.empty() ? NULL : strCuk.c_str()), isAutoRejoin, isNoGiveupRejoin, reinterpret_cast(strKey.c_str()), strKey.length() + 1, (PassPhrase.empty() ? NULL : PassPhrase.c_str()), &val64); + result = k2hdkc_full_cas64_get_wa(strConfig.c_str(), CntlPort, (strCuk.empty() ? NULL : strCuk.c_str()), isAutoRejoin, isNoGiveupRejoin, reinterpret_cast(strKey.c_str()), strKey.length() + 1, PassPhrase.c_str(), &val64); } } rescode = k2hdkc_get_lastres_code(); @@ -4200,13 +4217,13 @@ static bool CasGetCommand(k2hdkc_chmpx_h chmpxhandle, CASTYPE type, params_t& pa } }else{ if(CAS_TYPE_8 == type){ - result = k2hdkc_pm_cas8_get_wa(chmpxhandle, reinterpret_cast(strKey.c_str()), strKey.length() + 1, (PassPhrase.empty() ? NULL : PassPhrase.c_str()), &val8); + result = k2hdkc_pm_cas8_get_wa(chmpxhandle, reinterpret_cast(strKey.c_str()), strKey.length() + 1, PassPhrase.c_str(), &val8); }else if(CAS_TYPE_16 == type){ - result = k2hdkc_pm_cas16_get_wa(chmpxhandle, reinterpret_cast(strKey.c_str()), strKey.length() + 1, (PassPhrase.empty() ? NULL : PassPhrase.c_str()), &val16); + result = k2hdkc_pm_cas16_get_wa(chmpxhandle, reinterpret_cast(strKey.c_str()), strKey.length() + 1, PassPhrase.c_str(), &val16); }else if(CAS_TYPE_32 == type){ - result = k2hdkc_pm_cas32_get_wa(chmpxhandle, reinterpret_cast(strKey.c_str()), strKey.length() + 1, (PassPhrase.empty() ? NULL : PassPhrase.c_str()), &val32); + result = k2hdkc_pm_cas32_get_wa(chmpxhandle, reinterpret_cast(strKey.c_str()), strKey.length() + 1, PassPhrase.c_str(), &val32); }else{ // CAS_TYPE_64 == type - result = k2hdkc_pm_cas64_get_wa(chmpxhandle, reinterpret_cast(strKey.c_str()), strKey.length() + 1, (PassPhrase.empty() ? NULL : PassPhrase.c_str()), &val64); + result = k2hdkc_pm_cas64_get_wa(chmpxhandle, reinterpret_cast(strKey.c_str()), strKey.length() + 1, PassPhrase.c_str(), &val64); } } rescode = k2hdkc_get_res_code(chmpxhandle); @@ -5324,16 +5341,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 DKC_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 DKC_CLOSE(fd); return true; // for continue } } + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable DKC_CLOSE(fd); return true; } @@ -5365,6 +5388,8 @@ static bool LoadCommand(k2hdkc_chmpx_h chmpxhandle, ConsoleInput& InputIF, param } } } + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable DKC_CLOSE(fd); return true; } @@ -5457,24 +5482,32 @@ static bool CommandStringHandle(k2hdkc_chmpx_h chmpxhandle, ConsoleInput& InputI is_exit = true; }else if(opts.end() != opts.find("comlog")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!ComlogCommand(opts["comlog"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("dbglevel")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!DbglevelCommand(opts["dbglevel"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("print")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!PrintCommand(chmpxhandle, opts["print"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("dp")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!DirectPrintCommand(chmpxhandle, opts["dp"])){ CleanOptionMap(opts); return false; @@ -5487,144 +5520,192 @@ static bool CommandStringHandle(k2hdkc_chmpx_h chmpxhandle, ConsoleInput& InputI } }else if(opts.end() != opts.find("cf")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!CopyFileCommand(chmpxhandle, opts["cf"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("set")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!SetCommand(chmpxhandle, opts["set"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("dset")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!DirectSetCommand(chmpxhandle, opts["dset"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("sf")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!SetFileCommand(chmpxhandle, opts["sf"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("f")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!FillCommand(chmpxhandle, opts["f"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("fs")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!FillSubCommand(chmpxhandle, opts["fs"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("rm")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!RemoveCommand(chmpxhandle, opts["rm"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("ss")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!SetSubkeyCommand(chmpxhandle, opts["ss"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("rs")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!RemoveSubkeyCommand(chmpxhandle, opts["rs"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("ren")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!RenameCommand(chmpxhandle, opts["ren"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("q")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!QueueCommand(chmpxhandle, opts["q"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("kq")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!KeyQueueCommand(chmpxhandle, opts["kq"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("cas")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!CasCommand(chmpxhandle, CAS_TYPE_NO, opts["cas"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("cas8")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!CasCommand(chmpxhandle, CAS_TYPE_8, opts["cas8"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("cas16")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!CasCommand(chmpxhandle, CAS_TYPE_16, opts["cas16"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("cas32")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!CasCommand(chmpxhandle, CAS_TYPE_32, opts["cas32"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("cas64")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!CasCommand(chmpxhandle, CAS_TYPE_64, opts["cas64"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("st")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!StatusCommand(chmpxhandle, opts["st"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("history")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!HistoryCommand(InputIF)){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("save")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!SaveCommand(InputIF, opts["save"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("load")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!LoadCommand(chmpxhandle, InputIF, opts["load"], is_exit)){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("shell")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!ShellCommand()){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("echo")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!EchoCommand(opts["echo"])){ CleanOptionMap(opts); return false; } }else if(opts.end() != opts.find("sleep")){ + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!SleepCommand(opts["sleep"])){ CleanOptionMap(opts); return false; @@ -5679,6 +5760,8 @@ static bool CommandHandle(k2hdkc_chmpx_h chmpxhandle, ConsoleInput& InputIF) // exit shell InputIF.RemoveLastHistory(); // remove last(this) command from history InputIF.PutHistory("shell"); // and push "shell" command(replace history) + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress knownConditionTrueFalse if(!ShellCommand()){ return false; } @@ -5977,6 +6060,8 @@ int main(int argc, char** argv) if(!k2hdkc_close_chmpx_ex(chmpxhandle, isCleanupBup)){ ERR("Could not close(leave and close msgid) slave node chmpx, but continue for cleanup..."); } + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable chmpxhandle = K2HDKC_INVALID_HANDLE; // force }else{ if(!pSlave->Close()){ @@ -5986,6 +6071,8 @@ int main(int argc, char** argv) ERR("Could not leave slave node chmpx, but continue for cleanup..."); } DKC_DELETE(pSlave); // force + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress unreadVariable chmpxhandle = K2HDKC_INVALID_HANDLE; // force } }