Fixed #11734 (stylistic warnings from addons are not filtered when style is not enabled) (#5091)

This commit is contained in:
Daniel Marjamäki 2023-05-27 10:24:00 +02:00 committed by GitHub
parent 96c6276ce7
commit 6b9fac41f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 23 additions and 16 deletions

View File

@ -47,5 +47,5 @@ jobs:
cd %GITHUB_WORKSPACE%\addons\test
..\..\cppcheck.exe --dump -DDUMMY --suppress=uninitvar --inline-suppr misra\misra-test.c --std=c89 --platform=unix64
python3 ..\misra.py -verify misra\misra-test.c.dump
..\..\cppcheck.exe --addon=misra --inline-suppr --enable=information --error-exitcode=1 misra\misra-ctu-1-test.c misra\misra-ctu-2-test.c
..\..\cppcheck.exe --addon=misra --enable=style --inline-suppr --enable=information --error-exitcode=1 misra\misra-ctu-1-test.c misra\misra-ctu-2-test.c

View File

@ -380,7 +380,7 @@ jobs:
run: |
./cppcheck --addon=threadsafety addons/test/threadsafety
./cppcheck --addon=threadsafety --std=c++03 addons/test/threadsafety
./cppcheck --addon=misra --inline-suppr --enable=information --error-exitcode=1 addons/test/misra/misra-ctu-*-test.c
./cppcheck --addon=misra --enable=style --inline-suppr --enable=information --error-exitcode=1 addons/test/misra/misra-ctu-*-test.c
pushd addons/test
# We'll force C89 standard to enable an additional verification for
# rules 5.4 and 5.5 which have standard-dependent options.
@ -393,7 +393,7 @@ jobs:
python3 ../misra.py --rule-texts=misra/misra2012_rules_dummy_ascii.txt -verify misra/misra-test.cpp.dump
python3 ../misra.py --rule-texts=misra/misra2012_rules_dummy_utf8.txt -verify misra/misra-test.cpp.dump
python3 ../misra.py --rule-texts=misra/misra2012_rules_dummy_windows1250.txt -verify misra/misra-test.cpp.dump
../../cppcheck --addon=misra --platform=avr8 --error-exitcode=1 misra/misra-test-avr8.c
../../cppcheck --addon=misra --enable=style --platform=avr8 --error-exitcode=1 misra/misra-test-avr8.c
../../cppcheck --dump misc-test.cpp
python3 ../misc.py -verify misc-test.cpp.dump
../../cppcheck --dump naming_test.c

View File

@ -179,7 +179,7 @@ jobs:
run: |
.\cppcheck --addon=threadsafety addons\test\threadsafety || exit /b !errorlevel!
.\cppcheck --addon=threadsafety --std=c++03 addons\test\threadsafety || exit /b !errorlevel!
.\cppcheck --addon=misra --inline-suppr --enable=information --error-exitcode=1 addons\test\misra\misra-ctu-*-test.c || exit /b !errorlevel!
.\cppcheck --addon=misra --enable=style --inline-suppr --enable=information --error-exitcode=1 addons\test\misra\misra-ctu-*-test.c || exit /b !errorlevel!
cd addons\test
rem We'll force C89 standard to enable an additional verification for
rem rules 5.4 and 5.5 which have standard-dependent options.
@ -192,7 +192,7 @@ jobs:
python3 ..\misra.py --rule-texts=misra\misra2012_rules_dummy_ascii.txt -verify misra\misra-test.cpp.dump || exit /b !errorlevel!
python3 ..\misra.py --rule-texts=misra\misra2012_rules_dummy_utf8.txt -verify misra\misra-test.cpp.dump || exit /b !errorlevel!
python3 ..\misra.py --rule-texts=misra\misra2012_rules_dummy_windows1250.txt -verify misra\misra-test.cpp.dump || exit /b !errorlevel!
..\..\cppcheck --addon=misra --platform=avr8 --error-exitcode=1 misra\misra-test-avr8.c || exit /b !errorlevel!
..\..\cppcheck --addon=misra --enable=style --platform=avr8 --error-exitcode=1 misra\misra-test-avr8.c || exit /b !errorlevel!
..\..\cppcheck --dump misc-test.cpp || exit /b !errorlevel!
python3 ..\misc.py -verify misc-test.cpp.dump || exit /b !errorlevel!
..\..\cppcheck --dump naming_test.c || exit /b !errorlevel!

View File

@ -13,14 +13,14 @@ typedef int MISRA_5_6_VIOLATION;
// cppcheck-suppress misra-c2012-5.7
struct misra_5_7_violation_t {
int x;
int x; // cppcheck-suppress unusedStructMember
};
static misra_5_7_violation_t misra_5_7_use_type_1;
// #11443 - FP
static struct
{ // no warning
uint16_t x;
uint16_t x; // cppcheck-suppress unusedStructMember
} misra_5_7_false_positive_1;
// cppcheck-suppress misra-c2012-8.4

View File

@ -13,14 +13,14 @@ static MISRA_5_6_VIOLATION misra_5_6_x;
// cppcheck-suppress misra-c2012-5.7
struct misra_5_7_violation_t {
int x;
int x; // cppcheck-suppress unusedStructMember
};
static misra_5_7_violation_t misra_5_7_use_type_2;
// #11443 - FP
static struct
{ // no warning
uint16_t x;
uint16_t x; // cppcheck-suppress unusedStructMember
} misra_5_7_false_positive_2;
// cppcheck-suppress misra-c2012-5.8
@ -28,7 +28,7 @@ static int misra_5_8_var1;
// cppcheck-suppress misra-c2012-8.4
// cppcheck-suppress misra-c2012-5.8
void misra_5_8_f(void) {
// cppcheck-suppress misra-c2012-5.8
// cppcheck-suppress [misra-c2012-5.8, unusedVariable]
char misra_5_8_var2;
}

View File

@ -4,9 +4,9 @@
static void misra_10_4(void)
{
// #10480
char buf[1] = {'f'};
const char buf[1] = {'f'};
const char c = '0';
signed int x = buf[0] - c;
x = buf[0] - c;
}
static void misra_12_2(void) {

View File

@ -1489,6 +1489,8 @@ void CppCheck::executeAddons(const std::vector<std::string>& files)
errmsg.severity = Severity::fromString(severity);
if (errmsg.severity == Severity::SeverityType::none)
continue;
if (!mSettings.severity.isEnabled(errmsg.severity))
continue;
errmsg.file0 = ((files.size() == 1) ? files[0] : "");
reportErr(errmsg);

View File

@ -58,14 +58,19 @@ def test_absolute_path():
assert stderr == '[%s:5]: (error) Division by zero.\n' % filename
def test_addon_local_path():
ret, stdout, stderr = cppcheck_local(['--addon=misra', '--template=cppcheck1', '.'])
ret, stdout, stderr = cppcheck_local(['--addon=misra', '--enable=style', '--template=cppcheck1', '.'])
assert ret == 0, stdout
assert stderr == ('[main.c:5]: (error) Division by zero.\n'
'[main.c:1]: (style) misra violation (use --rule-texts=<file> to get proper output)\n')
def test_addon_local_path_not_enable():
ret, stdout, stderr = cppcheck_local(['--addon=misra', '--template=cppcheck1', '.'])
assert ret == 0, stdout
assert stderr == '[main.c:5]: (error) Division by zero.\n'
def test_addon_absolute_path():
prjpath = getAbsoluteProjectPath()
ret, stdout, stderr = cppcheck(['--addon=misra', '--template=cppcheck1', prjpath])
ret, stdout, stderr = cppcheck(['--addon=misra', '--enable=style', '--template=cppcheck1', prjpath])
filename = os.path.join(prjpath, 'main.c')
assert ret == 0, stdout
assert stderr == ('[%s:5]: (error) Division by zero.\n'
@ -73,7 +78,7 @@ def test_addon_absolute_path():
def test_addon_relative_path():
prjpath = getRelativeProjectPath()
ret, stdout, stderr = cppcheck(['--platform=native', '--addon=misra', '--template=cppcheck1', prjpath])
ret, stdout, stderr = cppcheck(['--platform=native', '--addon=misra', '--enable=style', '--template=cppcheck1', prjpath])
filename = os.path.join(prjpath, 'main.c')
assert ret == 0, stdout
assert stdout == ('Checking %s ...\n'
@ -84,7 +89,7 @@ def test_addon_relative_path():
def test_addon_with_gui_project():
project_file = 'helloworld/test.cppcheck'
create_gui_project_file(project_file, paths=['.'], addon='misra')
ret, stdout, stderr = cppcheck(['--platform=native', '--template=cppcheck1', '--project=' + project_file])
ret, stdout, stderr = cppcheck(['--platform=native', '--template=cppcheck1', '--enable=style', '--project=' + project_file])
filename = os.path.join('helloworld', 'main.c')
assert ret == 0, stdout
assert stdout == 'Checking %s ...\n' % filename