Skip to content

Commit

Permalink
Merge pull request #76 from ggtakec/update_shellcheck
Browse files Browse the repository at this point in the history
Added ShellCheck processing and reviewed cppcheck
  • Loading branch information
ggtakec authored Dec 6, 2022
2 parents 16e3dcf + 613e610 commit fd8ad28
Show file tree
Hide file tree
Showing 35 changed files with 1,719 additions and 1,086 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ jobs:
/bin/sh -c "$GITHUB_WORKSPACE/.github/workflows/build_helper.sh -os ${{ matrix.container }}"
dockerimage:
runs-on: ubuntu-latest
# [NOTE]
# We plan to update to ubuntu-latest (22.04) soon.
# Right now I am forced to use 20.04 as there are no relevant packages yet.
#
runs-on: ubuntu-20.04

#
# build matrix for containers
Expand Down
28 changes: 13 additions & 15 deletions .github/workflows/docker_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -777,21 +777,19 @@ fi
#
# Create dockerfile from template(Common conversion)
#
sed -e "s#%%GIT_DOMAIN_URL%%#${CI_GIT_URL}#g" \
-e "s#%%DOCKER_IMAGE_BASE%%#${CI_DOCKER_IMAGE_BASE}#g" \
-e "s#%%DOCKER_IMAGE_DEV_BASE%%#${CI_DOCKER_IMAGE_DEV_BASE}#g" \
-e "s#%%DOCKER_GIT_ORGANIZATION%%#${CI_DOCKER_GIT_ORGANIZATION}#g" \
-e "s#%%DOCKER_GIT_REPOSITORY%%#${CI_DOCKER_GIT_REPOSITORY}#g" \
-e "s#%%DOCKER_GIT_BRANCH%%#${CI_DOCKER_GIT_BRANCH}#g" \
-e "s#%%PKG_UPDATE%%#${PKGMGR_NAME} ${PKGMGR_UPDATE_OPT}#g" \
-e "s#%%PKG_INSTALL_BUILDER%%#${PKG_INSTALL_BUILDER_COMMAND}#g" \
-e "s#%%PKG_INSTALL_BIN%%#${PKG_INSTALL_BIN_COMMAND}#g" \
-e "s#%%UPDATE_LIBPATH%%#${UPDATE_LIBPATH}#g" \
-e "s#%%BUILD_ENV%%#${BUILDER_ENVIRONMENT}#g" \
"${SRCTOP}/${DOCKERFILE_TEMPL_SUBDIR}/${DOCKER_TEMPL_FILE}" > "${SRCTOP}/${DOCKER_FILE}"

# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
if ! sed -e "s#%%GIT_DOMAIN_URL%%#${CI_GIT_URL}#g" \
-e "s#%%DOCKER_IMAGE_BASE%%#${CI_DOCKER_IMAGE_BASE}#g" \
-e "s#%%DOCKER_IMAGE_DEV_BASE%%#${CI_DOCKER_IMAGE_DEV_BASE}#g" \
-e "s#%%DOCKER_GIT_ORGANIZATION%%#${CI_DOCKER_GIT_ORGANIZATION}#g" \
-e "s#%%DOCKER_GIT_REPOSITORY%%#${CI_DOCKER_GIT_REPOSITORY}#g" \
-e "s#%%DOCKER_GIT_BRANCH%%#${CI_DOCKER_GIT_BRANCH}#g" \
-e "s#%%PKG_UPDATE%%#${PKGMGR_NAME} ${PKGMGR_UPDATE_OPT}#g" \
-e "s#%%PKG_INSTALL_BUILDER%%#${PKG_INSTALL_BUILDER_COMMAND}#g" \
-e "s#%%PKG_INSTALL_BIN%%#${PKG_INSTALL_BIN_COMMAND}#g" \
-e "s#%%UPDATE_LIBPATH%%#${UPDATE_LIBPATH}#g" \
-e "s#%%BUILD_ENV%%#${BUILDER_ENVIRONMENT}#g" \
"${SRCTOP}/${DOCKERFILE_TEMPL_SUBDIR}/${DOCKER_TEMPL_FILE}" > "${SRCTOP}/${DOCKER_FILE}"; then

PRNERR "Failed to creating ${DOCKER_FILE} from ${DOCKER_TEMPL_FILE} (Common conversion)."
exit 1
fi
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/imagetypevars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,10 @@ custom_dockerfile_conversion()
fi
_TMP_DOCKERFILE_PATH="$1"

sed -e "s#%%CONFIGURE_FLAG%%#${BUILDER_CONFIGURE_FLAG}#g" \
-e "s#%%BUILD_FLAGS%%#${BUILDER_MAKE_FLAGS}#g" \
-i "${_TMP_DOCKERFILE_PATH}"
if ! sed -e "s#%%CONFIGURE_FLAG%%#${BUILDER_CONFIGURE_FLAG}#g" \
-e "s#%%BUILD_FLAGS%%#${BUILDER_MAKE_FLAGS}#g" \
-i "${_TMP_DOCKERFILE_PATH}"; then

# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
PRNERR "Failed to converting ${_TMP_DOCKERFILE_PATH}"
return 1
fi
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ostypevars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ fi
# RUN_POST_PACKAGE 0
# RUN_PUBLISH_PACKAGE 1
#
RUN_SHELLCHECK=0

#---------------------------------------------------------------
# Variables for each process
Expand Down
81 changes: 71 additions & 10 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,79 @@ SUBDIRS=lib docs tests buildutils

EXTRA_DIST=RELEASE_VERSION @CONFIGURECUSTOM@

CPPCHECK_CMD= cppcheck
CPPCHECK_OPT= --quiet \
--error-exitcode=1 \
--inline-suppr \
-j 4 \
--std=c++03 \
--xml \
--enable=warning,style,information,missingInclude
CPPCHECK_IGN=
.PHONY: cppcheck shellcheck

#
# CppCheck
#
# [NOTE]
# 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_CMD = cppcheck
CPPCHECK_TARGET = lib tests
CPPCHECK_BUILD_DIR = /tmp/cppcheck
CPPCHECK_BASE_OPT = --quiet \
--error-exitcode=1 \
--inline-suppr \
-j 4 \
--std=c++03 \
--xml
CPPCHECK_ENABLE_OPT = --enable=warning,style,information,missingInclude
CPPCHECK_IGNORE_OPT = --suppress=unmatchedSuppression

cppcheck:
$(CPPCHECK_CMD) $(CPPCHECK_OPT) $(CPPCHECK_IGN) $(SUBDIRS)
@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 \
echo "*** [INFO] cppcheck version below 1.8, so skip to run cppcheck."; \
else \
echo "*** Check all files with CppCheck"; \
if [ -d $(CPPCHECK_BUILD_DIR) ]; then \
rm -rf $(CPPCHECK_BUILD_DIR); \
fi; \
mkdir -p $(CPPCHECK_BUILD_DIR); \
$(CPPCHECK_CMD) $(CPPCHECK_BASE_OPT) $(CPPCHECK_ENABLE_OPT) $(CPPCHECK_IGNORE_OPT) --cppcheck-build-dir=$(CPPCHECK_BUILD_DIR) $(CPPCHECK_TARGET); \
rm -rf $(CPPCHECK_BUILD_DIR); \
fi; \
else \
echo "*** [WARNING] cppcheck is not installed, so skip to run cppcheck."; \
fi

#
# ShellCheck
#
# This make target executes shellchek on text files with the
# extension '*.sh' under the current directory(other than the
# '.git' directory) and executable files(text files other than
# the extension '*.sh').
#
SHELLCHECK_CMD = shellcheck
SHELLCHECK_BASE_OPT = --shell=sh
SHELLCHECK_IGN_OPT = --exclude=SC1117,SC1090,SC1091
SHELLCHECK_INCLUDE_IGN_OPT = --exclude=SC1117,SC1090,SC1091,SC2034,SC2148
SHELLCHECK_FILES_NO_SH = `grep -ril '^\#!/bin/sh' . | grep -v '\.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_FILES_SH = `grep -ril '^\#!/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_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 \
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; \
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; \
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; \
fi; \
echo " -> No error was detected."; \
echo ""; \
else \
echo "ShellCheck is not installed, so skip check by it."; \
echo ""; \
fi

#
# Local variables:
Expand Down
2 changes: 1 addition & 1 deletion buildutils/make_description.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ while IFS= read -r ONE_LINE; do
echo " .${ESC_LF_CHAR}"
fi
else
if [ "X${ONE_LINE}" = "X${REVERTED_LINE}" ]; then
if [ -n "${ONE_LINE}" ] && [ "${ONE_LINE}" = "${REVERTED_LINE}" ]; then
#
# This is new section
#
Expand Down
2 changes: 1 addition & 1 deletion buildutils/make_variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ elif [ "${PRGMODE}" = "DEBHELPER" ]; then
RESULT="debhelper (>= 9.20160709)${DEB_WITH_SYSTEMD_STRING}, autotools-dev"

elif [ "${OS_ID_STRING}" = "ubuntu" ]; then
if [ ${DEBHELPER_MAJOR_VER} -lt 10 ]; then
if [ "${DEBHELPER_MAJOR_VER}" -lt 10 ]; then
RESULT="debhelper (>= 9.20160709)${DEB_WITH_SYSTEMD_STRING}, autotools-dev"
else
RESULT="debhelper (>= 9.20160709)${DEB_WITH_SYSTEMD_STRING}"
Expand Down
3 changes: 0 additions & 3 deletions lib/k2harchive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ bool K2HArchive::Save(K2HShm* pShm) const
K2H_Free(byVal);
K2H_Free(bySKey);
K2H_Free(byAttrs);
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress unreadVariable
K2H_CLOSE(fd);

Expand Down Expand Up @@ -377,7 +376,6 @@ bool K2HArchive::Load(K2HShm* pShm) const
}
k2harchive_load_init_vals(pBinCom, byKey, byVal, bySKey, byAttrs, byExdata);

// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress unreadVariable
K2H_CLOSE(fd);

Expand All @@ -394,7 +392,6 @@ void* K2HArchive::ReadFile(int fd, size_t count, off_t offset) const

if(NULL == (pReadData = malloc(count))){
ERR_K2HPRN("Could not allocation memory.");
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress memleak
return NULL;
}
Expand Down
6 changes: 0 additions & 6 deletions lib/k2hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,6 @@ bool k2h_get_value_wp(k2h_h handle, const unsigned char* pkey, size_t keylength,
MSG_K2HPRN("Not found key or not have value.");
return false;
}
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress redundantAssignment
*pvallength = static_cast<size_t>(result);

Expand Down Expand Up @@ -561,7 +560,6 @@ bool k2h_get_value_np(k2h_h handle, const unsigned char* pkey, size_t keylength,
MSG_K2HPRN("Not found key or not have value.");
return false;
}
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress redundantAssignment
*pvallength = static_cast<size_t>(result);

Expand Down Expand Up @@ -635,7 +633,6 @@ bool k2h_get_value_wp_ext(k2h_h handle, const unsigned char* pkey, size_t keylen
MSG_K2HPRN("Not found key or not have value.");
return false;
}
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress redundantAssignment
*pvallength = static_cast<size_t>(result);

Expand Down Expand Up @@ -689,7 +686,6 @@ bool k2h_get_value_np_ext(k2h_h handle, const unsigned char* pkey, size_t keylen
MSG_K2HPRN("Not found key or not have value.");
return false;
}
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress redundantAssignment
*pvallength = static_cast<size_t>(result);

Expand Down Expand Up @@ -1028,7 +1024,6 @@ bool k2h_free_keyarray(char** pkeys)
return true;
}
for(char** ptmp = pkeys; *ptmp; ptmp++){
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress identicalInnerCondition
K2H_Free(*ptmp);
}
Expand Down Expand Up @@ -1693,7 +1688,6 @@ static bool k2h_find_get_ext(k2h_find_h findhandle, unsigned char** ppdata, size
ERR_K2HPRN("Could not get type(%d) data from k2h_find_h.", type);
return false;
}
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress redundantAssignment
*pdatalength = static_cast<size_t>(result);

Expand Down
2 changes: 0 additions & 2 deletions lib/k2hattrs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ K2HAttrs::iterator K2HAttrs::insert(const unsigned char* pkey, size_t keylength,
attr.vallength = vallength;
if(NULL == (attr.pkey = static_cast<unsigned char*>(malloc(attr.keylength)))){
ERR_K2HPRN("Could not allocate memory.");
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress memleak
return K2HAttrIterator(this, Attrs.end());
}
Expand All @@ -331,7 +330,6 @@ K2HAttrs::iterator K2HAttrs::insert(const unsigned char* pkey, size_t keylength,
if(NULL == (attr.pval = static_cast<unsigned char*>(malloc(attr.vallength)))){
ERR_K2HPRN("Could not allocate memory.");
K2H_Free(attr.pkey);
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress memleak
return K2HAttrIterator(this, Attrs.end());
}
Expand Down
1 change: 0 additions & 1 deletion lib/k2hdbg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ bool K2HDbgControl::SetDbgFile(const char* filepath)
FILE* newfp;
if(NULL == (newfp = fopen(filepath, "a+"))){
ERR_K2HPRN("Could not open debug file(%s). errno = %d", filepath, errno);
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress resourceLeak
return false;
}
Expand Down
3 changes: 0 additions & 3 deletions lib/k2hfilemonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ bool K2HFileMonitor::InitializeFileMonitor(PSFMONWRAP pfmonwrap, bool noupdate)

}else{
// could not open/create file
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress knownConditionTrueFalse
if(ENOENT != errno){
ERR_K2HPRN("Could not create/open file %s by errno(%d).", bup_monfile.c_str(), errno);
Expand Down Expand Up @@ -312,7 +311,6 @@ bool K2HFileMonitor::InitializeFileMonitor(PSFMONWRAP pfmonwrap, bool noupdate)
Unlock(OPEN_LOCK_POS);
CloseOnlyFile();

// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress knownConditionTrueFalse
if(ENOENT != errno){
ERR_K2HPRN("Could not get stat for file %s by errno(%d).", bup_monfile.c_str(), errno);
Expand Down Expand Up @@ -604,7 +602,6 @@ bool K2HFileMonitor::SetMonitorFilePath(void)
}

// make hash code
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress internalAstError
k2h_hash_t hash = K2H_HASH_FUNC(bup_shmfile.c_str(), bup_shmfile.length());

Expand Down
1 change: 0 additions & 1 deletion lib/k2hmmapinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ typedef struct k2h_mmap_info{
inline void k2h_mmap_info_list_add(PK2HMMAPINFO* ptop, PK2HMMAPINFO addinfo)
{
PK2HMMAPINFO parent = NULL;
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress nullPointerRedundantCheck
for(PK2HMMAPINFO base = *ptop; base; parent = base, base = base->next){
if(addinfo->file_offset < base->file_offset){
Expand Down
3 changes: 0 additions & 3 deletions lib/k2hpage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ unsigned char* K2HPage::AllocateData(ssize_t length)

if(NULL == (pPageData = static_cast<unsigned char*>(malloc(length)))){
ERR_K2HPRN("Could not allocation memory.");
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress memleak
return NULL;
}
Expand Down Expand Up @@ -213,14 +212,12 @@ bool K2HPage::CopyData(unsigned char** ppPageData, size_t* pLength) const
}
if(NULL == (*ppPageData = static_cast<unsigned char*>(malloc(sizeof(unsigned char) * DataLength)))){
ERR_K2HPRN("Could not allocation memory.");
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress memleak
return false;
}
memcpy(*ppPageData, pPageData, DataLength);
*pLength = DataLength;

// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress memleak
return true;
}
Expand Down
5 changes: 0 additions & 5 deletions lib/k2hpagefile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ using namespace std;
//---------------------------------------------------------
// Class Methods
//---------------------------------------------------------
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress constParameter
bool K2HPageFile::GetData(const K2HShm* pk2hshm, int fd, off_t offset, unsigned char** ppPageData, size_t* pLength)
{
Expand All @@ -50,13 +49,11 @@ bool K2HPageFile::GetData(const K2HShm* pk2hshm, int fd, off_t offset, unsigned
}
if(NULL == (*ppPageData = static_cast<unsigned char*>(malloc(k2hpage_obj.DataLength)))){
ERR_K2HPRN("Could not allocation memory.");
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress memleak
return false;
}
memcpy(*ppPageData, k2hpage_obj.pPageData, k2hpage_obj.DataLength);

// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress memleak
return true;
}
Expand Down Expand Up @@ -202,7 +199,6 @@ bool K2HPageFile::LoadPageHead(void)
PPAGEWRAP pPageWrap;
if(NULL == (pPageWrap = (PPAGEWRAP)malloc(sizeof(PAGEWRAP)))){
ERR_K2HPRN("Could not allocation memory.");
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress memleak
return false;
}
Expand All @@ -217,7 +213,6 @@ bool K2HPageFile::LoadPageHead(void)

isHeadLoaded = true;

// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress memleak
return true;
}
Expand Down
3 changes: 0 additions & 3 deletions lib/k2hpagemem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ using namespace std;
//---------------------------------------------------------
// Class Methods
//---------------------------------------------------------
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress constParameter
bool K2HPageMem::GetData(const K2HShm* pk2hshm, PPAGEHEAD reladdr, unsigned char** ppPageData, size_t* pLength)
{
Expand All @@ -48,13 +47,11 @@ bool K2HPageMem::GetData(const K2HShm* pk2hshm, PPAGEHEAD reladdr, unsigned char
}
if(NULL == (*ppPageData = static_cast<unsigned char*>(malloc(k2hpage_obj.DataLength)))){
ERR_K2HPRN("Could not allocation memory.");
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress memleak
return false;
}
memcpy(*ppPageData, k2hpage_obj.pPageData, k2hpage_obj.DataLength);

// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress memleak
return true;
}
Expand Down
Loading

0 comments on commit fd8ad28

Please sign in to comment.