40 lines
1.1 KiB
C
40 lines
1.1 KiB
C
|
|
// Test library configuration for gnu.cfg
|
|
//
|
|
// Usage:
|
|
// $ cppcheck --check-library --library=gnu --enable=information --enable=style --error-exitcode=1 --suppress=missingIncludeSystem --inline-suppr test/cfg/gnu.c
|
|
// =>
|
|
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
|
|
//
|
|
|
|
#include <string.h>
|
|
|
|
void bufferAccessOutOfBounds()
|
|
{
|
|
char buf[2];
|
|
// This is valid
|
|
sethostname(buf, 2);
|
|
// cppcheck-suppress bufferAccessOutOfBounds
|
|
sethostname(buf, 4);
|
|
}
|
|
|
|
void leakReturnValNotUsed()
|
|
{
|
|
// cppcheck-suppress unreadVariable
|
|
char* ptr = (char*)strdupa("test");
|
|
// cppcheck-suppress ignoredReturnValue
|
|
strdupa("test");
|
|
// cppcheck-suppress unreadVariable
|
|
char* ptr2 = (char*)strndupa("test", 1);
|
|
// cppcheck-suppress ignoredReturnValue
|
|
strndupa("test", 1);
|
|
// cppcheck-suppress ignoredReturnValue
|
|
// cppcheck-suppress nullPointer
|
|
strcasestr("test", NULL);
|
|
|
|
// cppcheck-suppress knownConditionTrueFalse
|
|
// cppcheck-suppress duplicateExpression
|
|
if (42 == __builtin_expect(42, 0))
|
|
return;
|
|
}
|