cppcheck/addons/test/misra/misra-suppressions1-test.c

34 lines
944 B
C
Raw Normal View History

Fix per file excludes (#1437) * MISRA: Allow printing of the suppressed rules to the console --show-suppressed-rules will print rules in the suppression rule list to the console sorted by rule number. * MISRA: Correct rule suppression for entire file scope The entire file scope suppression check was checking for the rule item list to be None instead of looking for None as an entry into the list. Correct this check and modify the documentation to explicitly state that an entry of None in the rule item list will set the scope for that suppression to be the entire file. * MISRA: Tests for checking per-file rule suppressions To run: ../../cppcheck --suppressions-list=suppressions.txt --dump misra-suppressions*-test.c python ../misra.py misra-suppressions*-test.c.dump There should be no violations reported * MISRA: Allow ignoring a prefix from file paths when suppression matching For environments that run cppcheck from the build system cppcheck may be passed a filename that is a complete path. Often this path will include a portion that is specific to the developer or to the environment where the project is located. The per-file suppression rules do filename matching based on the filename passed to cppcheck. To match any path information also has to be included into the suppressions file provided to cppcheck via the --suppressions-list= option. This limits the usefulness of the per-file based suppressions because it requires the suppression to be customized on a per instance basis. Add a option "--file-prefix" that allows a prefix to be excluded from the file path when doing the suppression filename matching. Example. Given the following structure: /test/path1/misra-suppressions1-test.c /test/path1/misra-suppressions2-test.c specifying --file-prefix /test/path1 will allow the use of misra-suppressions1-test.c and misra-suppressions2-test.c as filenames in the suppressions file without leading patch information but still match the suppression rule. * MISRA: Tests for --file-prefix option To run: ../../cppcheck --suppressions-list=suppressions.txt \ --dump misra-suppressions*-test.c \ path1/misra-suppressions*-test.c python ../misra.py misra-suppressions*-test.c.dump \ path1/misra-suppressions*-test.c There should be no violations reported
2018-10-18 09:17:57 +02:00
// To test:
// ../../cppcheck --suppressions-list=suppressions.txt --dump misra-suppressions*-test.c && python ../misra.py misra-suppressions*-test.c.dump
// There should be no violations reported
// This needs to stay at line number 7 to make the test pass
// If it is changed update suppressions.txt with the new line number
#include <stdio.h> //21.6
2021-07-10 20:10:44 +02:00
extern int misra_5_2_var_hides_var______31x;//8.4
Fix per file excludes (#1437) * MISRA: Allow printing of the suppressed rules to the console --show-suppressed-rules will print rules in the suppression rule list to the console sorted by rule number. * MISRA: Correct rule suppression for entire file scope The entire file scope suppression check was checking for the rule item list to be None instead of looking for None as an entry into the list. Correct this check and modify the documentation to explicitly state that an entry of None in the rule item list will set the scope for that suppression to be the entire file. * MISRA: Tests for checking per-file rule suppressions To run: ../../cppcheck --suppressions-list=suppressions.txt --dump misra-suppressions*-test.c python ../misra.py misra-suppressions*-test.c.dump There should be no violations reported * MISRA: Allow ignoring a prefix from file paths when suppression matching For environments that run cppcheck from the build system cppcheck may be passed a filename that is a complete path. Often this path will include a portion that is specific to the developer or to the environment where the project is located. The per-file suppression rules do filename matching based on the filename passed to cppcheck. To match any path information also has to be included into the suppressions file provided to cppcheck via the --suppressions-list= option. This limits the usefulness of the per-file based suppressions because it requires the suppression to be customized on a per instance basis. Add a option "--file-prefix" that allows a prefix to be excluded from the file path when doing the suppression filename matching. Example. Given the following structure: /test/path1/misra-suppressions1-test.c /test/path1/misra-suppressions2-test.c specifying --file-prefix /test/path1 will allow the use of misra-suppressions1-test.c and misra-suppressions2-test.c as filenames in the suppressions file without leading patch information but still match the suppression rule. * MISRA: Tests for --file-prefix option To run: ../../cppcheck --suppressions-list=suppressions.txt \ --dump misra-suppressions*-test.c \ path1/misra-suppressions*-test.c python ../misra.py misra-suppressions*-test.c.dump \ path1/misra-suppressions*-test.c There should be no violations reported
2018-10-18 09:17:57 +02:00
static int misra_5_2_var_hides_var______31y;//5.2
static int misra_5_2_function_hides_var_31x;
2021-07-10 20:10:44 +02:00
static void misra_5_2_function_hides_var_31y(void) {}//5.2
static void foo(void)
Fix per file excludes (#1437) * MISRA: Allow printing of the suppressed rules to the console --show-suppressed-rules will print rules in the suppression rule list to the console sorted by rule number. * MISRA: Correct rule suppression for entire file scope The entire file scope suppression check was checking for the rule item list to be None instead of looking for None as an entry into the list. Correct this check and modify the documentation to explicitly state that an entry of None in the rule item list will set the scope for that suppression to be the entire file. * MISRA: Tests for checking per-file rule suppressions To run: ../../cppcheck --suppressions-list=suppressions.txt --dump misra-suppressions*-test.c python ../misra.py misra-suppressions*-test.c.dump There should be no violations reported * MISRA: Allow ignoring a prefix from file paths when suppression matching For environments that run cppcheck from the build system cppcheck may be passed a filename that is a complete path. Often this path will include a portion that is specific to the developer or to the environment where the project is located. The per-file suppression rules do filename matching based on the filename passed to cppcheck. To match any path information also has to be included into the suppressions file provided to cppcheck via the --suppressions-list= option. This limits the usefulness of the per-file based suppressions because it requires the suppression to be customized on a per instance basis. Add a option "--file-prefix" that allows a prefix to be excluded from the file path when doing the suppression filename matching. Example. Given the following structure: /test/path1/misra-suppressions1-test.c /test/path1/misra-suppressions2-test.c specifying --file-prefix /test/path1 will allow the use of misra-suppressions1-test.c and misra-suppressions2-test.c as filenames in the suppressions file without leading patch information but still match the suppression rule. * MISRA: Tests for --file-prefix option To run: ../../cppcheck --suppressions-list=suppressions.txt \ --dump misra-suppressions*-test.c \ path1/misra-suppressions*-test.c python ../misra.py misra-suppressions*-test.c.dump \ path1/misra-suppressions*-test.c There should be no violations reported
2018-10-18 09:17:57 +02:00
{
int i;
switch(misra_5_2_func1()) //16.4 16.6
{
case 1:
{
do
{
for(i = 0; i < 10; i++)
{
if(misra_5_2_func3()) //17.3
Fix per file excludes (#1437) * MISRA: Allow printing of the suppressed rules to the console --show-suppressed-rules will print rules in the suppression rule list to the console sorted by rule number. * MISRA: Correct rule suppression for entire file scope The entire file scope suppression check was checking for the rule item list to be None instead of looking for None as an entry into the list. Correct this check and modify the documentation to explicitly state that an entry of None in the rule item list will set the scope for that suppression to be the entire file. * MISRA: Tests for checking per-file rule suppressions To run: ../../cppcheck --suppressions-list=suppressions.txt --dump misra-suppressions*-test.c python ../misra.py misra-suppressions*-test.c.dump There should be no violations reported * MISRA: Allow ignoring a prefix from file paths when suppression matching For environments that run cppcheck from the build system cppcheck may be passed a filename that is a complete path. Often this path will include a portion that is specific to the developer or to the environment where the project is located. The per-file suppression rules do filename matching based on the filename passed to cppcheck. To match any path information also has to be included into the suppressions file provided to cppcheck via the --suppressions-list= option. This limits the usefulness of the per-file based suppressions because it requires the suppression to be customized on a per instance basis. Add a option "--file-prefix" that allows a prefix to be excluded from the file path when doing the suppression filename matching. Example. Given the following structure: /test/path1/misra-suppressions1-test.c /test/path1/misra-suppressions2-test.c specifying --file-prefix /test/path1 will allow the use of misra-suppressions1-test.c and misra-suppressions2-test.c as filenames in the suppressions file without leading patch information but still match the suppression rule. * MISRA: Tests for --file-prefix option To run: ../../cppcheck --suppressions-list=suppressions.txt \ --dump misra-suppressions*-test.c \ path1/misra-suppressions*-test.c python ../misra.py misra-suppressions*-test.c.dump \ path1/misra-suppressions*-test.c There should be no violations reported
2018-10-18 09:17:57 +02:00
{
int misra_5_2_var_hides_var_1____31x;
int misra_5_2_var_hides_var_1____31y;//5.2
}
}
} while(misra_5_2_func2()); //17.3
Fix per file excludes (#1437) * MISRA: Allow printing of the suppressed rules to the console --show-suppressed-rules will print rules in the suppression rule list to the console sorted by rule number. * MISRA: Correct rule suppression for entire file scope The entire file scope suppression check was checking for the rule item list to be None instead of looking for None as an entry into the list. Correct this check and modify the documentation to explicitly state that an entry of None in the rule item list will set the scope for that suppression to be the entire file. * MISRA: Tests for checking per-file rule suppressions To run: ../../cppcheck --suppressions-list=suppressions.txt --dump misra-suppressions*-test.c python ../misra.py misra-suppressions*-test.c.dump There should be no violations reported * MISRA: Allow ignoring a prefix from file paths when suppression matching For environments that run cppcheck from the build system cppcheck may be passed a filename that is a complete path. Often this path will include a portion that is specific to the developer or to the environment where the project is located. The per-file suppression rules do filename matching based on the filename passed to cppcheck. To match any path information also has to be included into the suppressions file provided to cppcheck via the --suppressions-list= option. This limits the usefulness of the per-file based suppressions because it requires the suppression to be customized on a per instance basis. Add a option "--file-prefix" that allows a prefix to be excluded from the file path when doing the suppression filename matching. Example. Given the following structure: /test/path1/misra-suppressions1-test.c /test/path1/misra-suppressions2-test.c specifying --file-prefix /test/path1 will allow the use of misra-suppressions1-test.c and misra-suppressions2-test.c as filenames in the suppressions file without leading patch information but still match the suppression rule. * MISRA: Tests for --file-prefix option To run: ../../cppcheck --suppressions-list=suppressions.txt \ --dump misra-suppressions*-test.c \ path1/misra-suppressions*-test.c python ../misra.py misra-suppressions*-test.c.dump \ path1/misra-suppressions*-test.c There should be no violations reported
2018-10-18 09:17:57 +02:00
}
}
}