Skip to content

Commit

Permalink
Use clang for static code analysis during lint testing.
Browse files Browse the repository at this point in the history
Nothing found except for some functions that should have been marked __noreturn__.
  • Loading branch information
dwsteele committed Mar 18, 2018
1 parent f0451c1 commit 0c31371
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 13 deletions.
4 changes: 4 additions & 0 deletions doc/xml/release.xml
Expand Up @@ -146,6 +146,10 @@
<release-item>
<p>Add CentOS/RHEL package builds.</p>
</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-development-list>
Expand Down
2 changes: 1 addition & 1 deletion src/common/error.c
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/common/error.h
Expand Up @@ -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
8 changes: 4 additions & 4 deletions src/common/memContext.c
Expand Up @@ -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
Expand All @@ -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?
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/common/regExp.c
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/config/parse.c
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions test/lib/pgBackRestTest/Common/ContainerTest.pm
Expand Up @@ -359,6 +359,10 @@ sub containerBuild
{
$strScript .= ' libperl5.14';
}
elsif ($strOS eq VM_U16)
{
$strScript .= ' clang-5.0';
}
}

#---------------------------------------------------------------------------------------------------------------------------
Expand Down
9 changes: 8 additions & 1 deletion test/test.pl
Expand Up @@ -535,8 +535,15 @@ =head1 SYNOPSIS
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(
Expand Down
4 changes: 2 additions & 2 deletions test/travis.pl
Expand Up @@ -142,10 +142,10 @@ sub processEnd
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';
}
Expand Down

0 comments on commit 0c31371

Please sign in to comment.