1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-30 05:39:12 +02:00

Use clang for static code analysis during lint testing.

Nothing found except for some functions that should have been marked __noreturn__.
This commit is contained in:
David Steele 2018-03-18 13:32:19 -04:00
parent f0451c1494
commit 0c313713b1
9 changed files with 29 additions and 13 deletions

View File

@ -146,6 +146,10 @@
<release-item> <release-item>
<p>Add CentOS/RHEL package builds.</p> <p>Add CentOS/RHEL package builds.</p>
</release-item> </release-item>
<release-item>
<p>Use clang for static code analysis during lint testing. Nothing found except for some functions that should have been marked <code>__noreturn__</code>.</p>
</release-item>
</release-feature-list> </release-feature-list>
<release-development-list> <release-development-list>

View File

@ -358,7 +358,7 @@ errorInternalThrow(const ErrorType *errorType, const char *fileName, int fileLin
// Propogate the error // Propogate the error
errorInternalPropagate(); errorInternalPropagate();
} // {uncoverable - errorInternalPropagate() does not return} }
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Throw an error Throw an error

View File

@ -144,8 +144,9 @@ bool errorInternalStateTry();
bool errorInternalStateCatch(const ErrorType *errorTypeCatch); bool errorInternalStateCatch(const ErrorType *errorTypeCatch);
bool errorInternalStateFinal(); bool errorInternalStateFinal();
bool errorInternalProcess(bool catch); bool errorInternalProcess(bool catch);
void errorInternalPropagate(); void errorInternalPropagate() __attribute__((__noreturn__));
void errorInternalThrow(const ErrorType *errorType, const char *fileName, int fileLine, const char *format, ...); 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, ...); void errorInternalThrowSys(int result, const ErrorType *errorType, const char *fileName, int fileLine, const char *format, ...);
#endif #endif

View File

@ -67,7 +67,7 @@ memAllocInternal(size_t size, bool zero)
void *buffer = malloc(size); void *buffer = malloc(size);
// Error when malloc fails // Error when malloc fails
if (!buffer) if (buffer == NULL)
THROW(MemoryError, "unable to allocate %lu bytes", size); THROW(MemoryError, "unable to allocate %lu bytes", size);
// Zero the memory when requested // 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); void *bufferNew = realloc(bufferOld, sizeNew);
// Error when realloc fails // Error when realloc fails
if(!bufferNew) if (bufferNew == NULL)
THROW(MemoryError, "unable to reallocate %lu bytes", sizeNew); 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? // 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) memFreeInternal(void *buffer)
{ {
// Error if pointer is null // Error if pointer is null
if(!buffer) if (buffer == NULL)
THROW(MemoryError, "unable to free null pointer"); THROW(MemoryError, "unable to free null pointer");
// Free the buffer // Free the buffer
@ -265,7 +265,7 @@ static unsigned int
memFind(const void *buffer) memFind(const void *buffer)
{ {
// Error if buffer is null // Error if buffer is null
if (!buffer) if (buffer == NULL)
THROW(AssertError, "unable to find null allocation"); THROW(AssertError, "unable to find null allocation");
// Find memory allocation // Find memory allocation

View File

@ -26,7 +26,7 @@ regExpError(int error)
char buffer[4096]; char buffer[4096];
regerror(error, NULL, buffer, sizeof(buffer)); regerror(error, NULL, buffer, sizeof(buffer));
THROW(FormatError, buffer); THROW(FormatError, buffer);
} // {uncoverable - THROW() does not return} }
/*********************************************************************************************************************************** /***********************************************************************************************************************************
New regular expression handler New regular expression handler

View File

@ -150,12 +150,12 @@ configParse(unsigned int argListSize, const char *argList[])
// If the option is unknown then error // If the option is unknown then error
case '?': case '?':
THROW(OptionInvalidError, "invalid option '%s'", argList[optind - 1]); 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 // If the option is missing an argument then error
case ':': case ':':
THROW(OptionInvalidError, "option '%s' requires argument", argList[optind - 1]); THROW(OptionInvalidError, "option '%s' requires argument", argList[optind - 1]);
break; // {uncoverable - case statement does not return} break;
// Parse valid option // Parse valid option
default: default:

View File

@ -359,6 +359,10 @@ sub containerBuild
{ {
$strScript .= ' libperl5.14'; $strScript .= ' libperl5.14';
} }
elsif ($strOS eq VM_U16)
{
$strScript .= ' clang-5.0';
}
} }
#--------------------------------------------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------------------------------

View File

@ -535,8 +535,15 @@ eval
executeTest("rsync -rt ${strBackRestBase}/${strBinSrcPath}/* ${strBinPath}/${strBuildVM}/${strBinSrcPath}"); executeTest("rsync -rt ${strBackRestBase}/${strBinSrcPath}/* ${strBinPath}/${strBuildVM}/${strBinSrcPath}");
} }
if (vmCoverage($strVm) && !$bNoLint)
{
&log(INFO, " clang static analyzer ${strBuildVM} (${strBuildPath})");
}
executeTest( 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}); {bShowOutputAsync => $bLogDetail});
executeTest( executeTest(

View File

@ -142,10 +142,10 @@ eval
confess &log(ERROR, '--vm is required'); confess &log(ERROR, '--vm is required');
} }
# Only lint on CO6 # Only lint on U16
my $strParam = undef; my $strParam = undef;
if ($strVm ne VM_CO6) if ($strVm ne VM_U16)
{ {
$strParam .= '--no-lint'; $strParam .= '--no-lint';
} }