Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions addons/misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,20 +478,20 @@ def rawlink(rawtoken):
'wctype.h': C99_STDLIB_IDENTIFIERS['wctype.h'],
}

def isStdLibId(id_, standard='c99'):
id_lists = []
def getStdLib(standard):
if standard == 'c89':
id_lists = C90_STDLIB_IDENTIFIERS.values()
elif standard == 'c99':
id_lists = C99_STDLIB_IDENTIFIERS.values()
else:
id_lists = C11_STDLIB_IDENTIFIERS.values()
return C90_STDLIB_IDENTIFIERS
if standard == 'c99':
return C99_STDLIB_IDENTIFIERS
return C11_STDLIB_IDENTIFIERS

def isStdLibId(id_, standard='c99'):
id_lists = getStdLib(standard).values()
for l in id_lists:
if id_ in l:
return True
return False


# Reserved keywords defined in ISO/IEC9899:1990 -- ch 6.1.1
C90_KEYWORDS = {
'auto', 'break', 'case', 'char', 'const', 'continue', 'default', 'do',
Expand Down Expand Up @@ -3964,12 +3964,13 @@ def misra_21_5(self, data):
self.reportError(directive, 21, 5)

def misra_21_6(self, data):
dir_stdio = findInclude(data.directives, '<stdio.h>')
dir_wchar = findInclude(data.directives, '<wchar.h>')
if dir_stdio:
self.reportError(dir_stdio, 21, 6)
if dir_wchar:
self.reportError(dir_wchar, 21, 6)
for token in data.tokenlist:
if not isFunctionCall(token) or token.previous.function:
continue
standard_id = getStdLib(data.standards.c)
funcname = token.previous.str
if funcname in standard_id.get("stdio.h", []) or funcname in standard_id.get("wchar.h", []):
self.reportError(token, 21, 6)

def misra_21_7(self, data):
for token in data.tokenlist:
Expand Down
18 changes: 9 additions & 9 deletions addons/test/misra/misra-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@

#include <setjmp.h> // 21.4
#include <signal.h> // 21.5
#include <stdio.h> //21.6
#include <wchar.h> //21.6
#include <stdio.h>
#include <wchar.h>
#include <time.h> // 21.10
#include <tgmath.h> // 21.11
#include <fenv.h>
Expand Down Expand Up @@ -134,7 +134,7 @@ static void misra_3_2(int enable)
++y; // This is hidden if trigraph replacement is active
}

(void)printf("x=%i, y=%i\n", x, y);
(void)printf("x=%i, y=%i\n", x, y); //21.6
}

extern int misra_5_1_extern_var_hides_var_x;
Expand Down Expand Up @@ -209,9 +209,9 @@ int c41_15 = 'a'; // 10.3 8.4

static void misra_4_1(void)
{
(void)printf("\x41g"); // 4.1
(void)printf("\x41\x42");
(void)printf("\x41" "g");
(void)printf("\x41g"); // 4.1 21.6
(void)printf("\x41\x42"); //21.6
(void)printf("\x41" "g"); //21.6
}

const char *s42_1 = "String containing trigraphs ??-??-??"; // 4.2 8.4
Expand All @@ -220,8 +220,8 @@ const char *s42_3 = "No trigraph?(?'?)"; // 8.4

static void misra_4_2(void)
{
(void)printf("??=Trigraph\n"); // 4.2
(void)printf("No?/Trigraph\n");
(void)printf("??=Trigraph\n"); // 4.2 21.6
(void)printf("No?/Trigraph\n"); //21.6
}

#define misra_5_4_macro_hides_macro__31x 1
Expand Down Expand Up @@ -965,7 +965,7 @@ void misra_12_3(int a, int b, int c) {
int a41 = MISRA_12_3_FN3_2(a34, a35), a42; // 12.3
int a43, a44 = MISRA_12_3_FN3_2(a34, a35); // 12.3

MISRA_12_3_FN3_2_MSG(fprintf(stderr, "test\n")); // 12.3
MISRA_12_3_FN3_2_MSG(fprintf(stderr, "test\n")); // 12.3 21.6

f((1,2),3); // TODO

Expand Down
8 changes: 4 additions & 4 deletions test/cli/helloworld_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_addon_local_path():
ret, stdout, stderr = cppcheck(args, cwd=__proj_dir)
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')
'[main.c:4]: (style) misra violation (use --rule-texts=<file> to get proper output)\n')

def test_addon_local_path_not_enable():
args = [
Expand All @@ -91,7 +91,7 @@ def test_addon_absolute_path():
filename = os.path.join(__proj_dir, 'main.c')
assert ret == 0, stdout
assert stderr == ('[%s:5]: (error) Division by zero.\n'
'[%s:1]: (style) misra violation (use --rule-texts=<file> to get proper output)\n' % (filename, filename))
'[%s:4]: (style) misra violation (use --rule-texts=<file> to get proper output)\n' % (filename, filename))

def test_addon_relative_path():
args = [
Expand All @@ -106,7 +106,7 @@ def test_addon_relative_path():
assert stdout == ('Checking %s ...\n'
'Checking %s: SOME_CONFIG...\n' % (filename, filename))
assert stderr == ('[%s:5]: (error) Division by zero.\n'
'[%s:1]: (style) misra violation (use --rule-texts=<file> to get proper output)\n' % (filename, filename))
'[%s:4]: (style) misra violation (use --rule-texts=<file> to get proper output)\n' % (filename, filename))

def test_addon_with_gui_project():
project_file = os.path.join('helloworld', 'test.cppcheck')
Expand All @@ -123,7 +123,7 @@ def test_addon_with_gui_project():
assert ret == 0, stdout
assert stdout == 'Checking %s ...\n' % filename
assert stderr == ('[%s:5]: (error) Division by zero.\n'
'[%s:1]: (style) misra violation (use --rule-texts=<file> to get proper output)\n' % (filename, filename))
'[%s:4]: (style) misra violation (use --rule-texts=<file> to get proper output)\n' % (filename, filename))

def test_basepath_relative_path():
args = [
Expand Down