Added rule 21.6 and 21.10 (#1243)

This commit is contained in:
Swasti Shrivastava 2018-05-20 18:14:12 +05:30 committed by Daniel Marjamäki
parent 672d0433a4
commit 00970274b2
2 changed files with 26 additions and 1 deletions

View File

@ -1308,7 +1308,7 @@ def misra_20_14(data):
elif directive.str == '#endif': elif directive.str == '#endif':
if len(ifStack) == 0: if len(ifStack) == 0:
reportError(directive, 20, 14) reportError(directive, 20, 14)
elif directive.file != ifStack[-1].file: elif directive.file != ifStack[-1].file:
reportError(directive, 20, 14) reportError(directive, 20, 14)
ifStack.pop() ifStack.pop()
@ -1330,6 +1330,15 @@ def misra_21_5(data):
reportError(directive, 21, 5) reportError(directive, 21, 5)
def misra_21_6(data):
dir_stdio = findInclude(data.directives, '<stdio.h>')
dir_wchar = findInclude(data.directives, '<wchar.h>')
if dir_stdio:
reportError(dir_stdio, 21, 6)
if dir_wchar:
reportError(dir_wchar, 21, 6)
def misra_21_7(data): def misra_21_7(data):
for token in data.tokenlist: for token in data.tokenlist:
if isFunctionCall(token) and (token.astOperand1.str in {'atof', 'atoi', 'atol', 'atoll'}): if isFunctionCall(token) and (token.astOperand1.str in {'atof', 'atoi', 'atol', 'atoll'}):
@ -1348,6 +1357,16 @@ def misra_21_9(data):
reportError(token, 21, 9) reportError(token, 21, 9)
def misra_21_10(data):
directive = findInclude(data.directives, '<time.h>')
if directive:
reportError(directive, 21, 10)
for token in data.tokenlist:
if (token.str == 'wcsftime') and token.next and token.next.str == '(':
reportError(token, 21, 10)
def misra_21_11(data): def misra_21_11(data):
directive = findInclude(data.directives, '<tgmath.h>') directive = findInclude(data.directives, '<tgmath.h>')
if directive: if directive:
@ -1603,9 +1622,11 @@ for arg in sys.argv[1:]:
misra_21_3(cfg) misra_21_3(cfg)
misra_21_4(cfg) misra_21_4(cfg)
misra_21_5(cfg) misra_21_5(cfg)
misra_21_6(cfg)
misra_21_7(cfg) misra_21_7(cfg)
misra_21_8(cfg) misra_21_8(cfg)
misra_21_9(cfg) misra_21_9(cfg)
misra_21_10(cfg)
misra_21_11(cfg) misra_21_11(cfg)
# 22.4 is already covered by Cppcheck writeReadOnlyFile # 22.4 is already covered by Cppcheck writeReadOnlyFile
if VERIFY: if VERIFY:

View File

@ -5,8 +5,12 @@
#include /*abc*/ "file.h" // 20.3 #include /*abc*/ "file.h" // 20.3
#include <setjmp.h> // 21.4 #include <setjmp.h> // 21.4
#include <signal.h> // 21.5 #include <signal.h> // 21.5
#include <stdio.h> //21.6
#include <wchar.h> //21.6
#include <time.h> // 21.10
#include <tgmath.h> // 21.11 #include <tgmath.h> // 21.11
typedef unsigned char u8; typedef unsigned char u8;
typedef unsigned short u16; typedef unsigned short u16;
typedef unsigned int u32; typedef unsigned int u32;