From 0c313713b1f40f09a970bee70e4e1ca3bcbbe082 Mon Sep 17 00:00:00 2001 From: David Steele Date: Sun, 18 Mar 2018 13:32:19 -0400 Subject: [PATCH] Use clang for static code analysis during lint testing. Nothing found except for some functions that should have been marked __noreturn__. --- doc/xml/release.xml | 4 ++++ src/common/error.c | 2 +- src/common/error.h | 5 +++-- src/common/memContext.c | 8 ++++---- src/common/regExp.c | 2 +- src/config/parse.c | 4 ++-- test/lib/pgBackRestTest/Common/ContainerTest.pm | 4 ++++ test/test.pl | 9 ++++++++- test/travis.pl | 4 ++-- 9 files changed, 29 insertions(+), 13 deletions(-) diff --git a/doc/xml/release.xml b/doc/xml/release.xml index c6aebb8f8..56cd660bc 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -146,6 +146,10 @@

Add CentOS/RHEL package builds.

+ + +

Use clang for static code analysis during lint testing. Nothing found except for some functions that should have been marked __noreturn__.

+
diff --git a/src/common/error.c b/src/common/error.c index 695ecb164..34a544be6 100644 --- a/src/common/error.c +++ b/src/common/error.c @@ -358,7 +358,7 @@ errorInternalThrow(const ErrorType *errorType, const char *fileName, int fileLin // Propogate the error errorInternalPropagate(); -} // {uncoverable - errorInternalPropagate() does not return} +} /*********************************************************************************************************************************** Throw an error diff --git a/src/common/error.h b/src/common/error.h index d12cc462f..3ae40ea3b 100644 --- a/src/common/error.h +++ b/src/common/error.h @@ -144,8 +144,9 @@ bool errorInternalStateTry(); bool errorInternalStateCatch(const ErrorType *errorTypeCatch); bool errorInternalStateFinal(); bool errorInternalProcess(bool catch); -void errorInternalPropagate(); -void errorInternalThrow(const ErrorType *errorType, const char *fileName, int fileLine, const char *format, ...); +void errorInternalPropagate() __attribute__((__noreturn__)); +void errorInternalThrow( + const ErrorType *errorType, const char *fileName, int fileLine, const char *format, ...) __attribute__((__noreturn__)); void errorInternalThrowSys(int result, const ErrorType *errorType, const char *fileName, int fileLine, const char *format, ...); #endif diff --git a/src/common/memContext.c b/src/common/memContext.c index b8d401fc6..594630e9d 100644 --- a/src/common/memContext.c +++ b/src/common/memContext.c @@ -67,7 +67,7 @@ memAllocInternal(size_t size, bool zero) void *buffer = malloc(size); // Error when malloc fails - if (!buffer) + if (buffer == NULL) THROW(MemoryError, "unable to allocate %lu bytes", size); // Zero the memory when requested @@ -88,7 +88,7 @@ memReAllocInternal(void *bufferOld, size_t sizeOld, size_t sizeNew, bool zeroNew void *bufferNew = realloc(bufferOld, sizeNew); // Error when realloc fails - if(!bufferNew) + if (bufferNew == NULL) THROW(MemoryError, "unable to reallocate %lu bytes", sizeNew); // Zero the new memory when requested - old memory is left untouched else why bother with a realloc? @@ -106,7 +106,7 @@ static void memFreeInternal(void *buffer) { // Error if pointer is null - if(!buffer) + if (buffer == NULL) THROW(MemoryError, "unable to free null pointer"); // Free the buffer @@ -265,7 +265,7 @@ static unsigned int memFind(const void *buffer) { // Error if buffer is null - if (!buffer) + if (buffer == NULL) THROW(AssertError, "unable to find null allocation"); // Find memory allocation diff --git a/src/common/regExp.c b/src/common/regExp.c index b74c4464c..c39d577e2 100644 --- a/src/common/regExp.c +++ b/src/common/regExp.c @@ -26,7 +26,7 @@ regExpError(int error) char buffer[4096]; regerror(error, NULL, buffer, sizeof(buffer)); THROW(FormatError, buffer); -} // {uncoverable - THROW() does not return} +} /*********************************************************************************************************************************** New regular expression handler diff --git a/src/config/parse.c b/src/config/parse.c index a32af92aa..1964b4904 100644 --- a/src/config/parse.c +++ b/src/config/parse.c @@ -150,12 +150,12 @@ configParse(unsigned int argListSize, const char *argList[]) // If the option is unknown then error case '?': THROW(OptionInvalidError, "invalid option '%s'", argList[optind - 1]); - break; // {uncoverable - case statement does not return} + break; // If the option is missing an argument then error case ':': THROW(OptionInvalidError, "option '%s' requires argument", argList[optind - 1]); - break; // {uncoverable - case statement does not return} + break; // Parse valid option default: diff --git a/test/lib/pgBackRestTest/Common/ContainerTest.pm b/test/lib/pgBackRestTest/Common/ContainerTest.pm index fbc48191c..9e03fed80 100755 --- a/test/lib/pgBackRestTest/Common/ContainerTest.pm +++ b/test/lib/pgBackRestTest/Common/ContainerTest.pm @@ -359,6 +359,10 @@ sub containerBuild { $strScript .= ' libperl5.14'; } + elsif ($strOS eq VM_U16) + { + $strScript .= ' clang-5.0'; + } } #--------------------------------------------------------------------------------------------------------------------------- diff --git a/test/test.pl b/test/test.pl index 80ae27715..f8e396aa3 100755 --- a/test/test.pl +++ b/test/test.pl @@ -535,8 +535,15 @@ eval executeTest("rsync -rt ${strBackRestBase}/${strBinSrcPath}/* ${strBinPath}/${strBuildVM}/${strBinSrcPath}"); } + if (vmCoverage($strVm) && !$bNoLint) + { + &log(INFO, " clang static analyzer ${strBuildVM} (${strBuildPath})"); + } + executeTest( - "docker exec -i test-build make --silent --directory ${strBuildPath} CEXTRA=-g CDEBUG=", + 'docker exec -i test-build' . + (vmCoverage($strVm) && !$bNoLint ? ' scan-build-5.0' : '') . + " make --silent --directory ${strBuildPath} CEXTRA=-g CDEBUG=", {bShowOutputAsync => $bLogDetail}); executeTest( diff --git a/test/travis.pl b/test/travis.pl index c8f3e7a6f..df7eb57d2 100755 --- a/test/travis.pl +++ b/test/travis.pl @@ -142,10 +142,10 @@ eval confess &log(ERROR, '--vm is required'); } - # Only lint on CO6 + # Only lint on U16 my $strParam = undef; - if ($strVm ne VM_CO6) + if ($strVm ne VM_U16) { $strParam .= '--no-lint'; }