Skip to content

Commit 0097027

Browse files
swasti16danmar
authored andcommitted
Added rule 21.6 and 21.10 (danmar#1243)
1 parent 672d043 commit 0097027

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

addons/misra.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ def misra_20_14(data):
13081308
elif directive.str == '#endif':
13091309
if len(ifStack) == 0:
13101310
reportError(directive, 20, 14)
1311-
elif directive.file != ifStack[-1].file:
1311+
elif directive.file != ifStack[-1].file:
13121312
reportError(directive, 20, 14)
13131313
ifStack.pop()
13141314

@@ -1330,6 +1330,15 @@ def misra_21_5(data):
13301330
reportError(directive, 21, 5)
13311331

13321332

1333+
def misra_21_6(data):
1334+
dir_stdio = findInclude(data.directives, '<stdio.h>')
1335+
dir_wchar = findInclude(data.directives, '<wchar.h>')
1336+
if dir_stdio:
1337+
reportError(dir_stdio, 21, 6)
1338+
if dir_wchar:
1339+
reportError(dir_wchar, 21, 6)
1340+
1341+
13331342
def misra_21_7(data):
13341343
for token in data.tokenlist:
13351344
if isFunctionCall(token) and (token.astOperand1.str in {'atof', 'atoi', 'atol', 'atoll'}):
@@ -1348,6 +1357,16 @@ def misra_21_9(data):
13481357
reportError(token, 21, 9)
13491358

13501359

1360+
def misra_21_10(data):
1361+
directive = findInclude(data.directives, '<time.h>')
1362+
if directive:
1363+
reportError(directive, 21, 10)
1364+
1365+
for token in data.tokenlist:
1366+
if (token.str == 'wcsftime') and token.next and token.next.str == '(':
1367+
reportError(token, 21, 10)
1368+
1369+
13511370
def misra_21_11(data):
13521371
directive = findInclude(data.directives, '<tgmath.h>')
13531372
if directive:
@@ -1603,9 +1622,11 @@ def generateTable():
16031622
misra_21_3(cfg)
16041623
misra_21_4(cfg)
16051624
misra_21_5(cfg)
1625+
misra_21_6(cfg)
16061626
misra_21_7(cfg)
16071627
misra_21_8(cfg)
16081628
misra_21_9(cfg)
1629+
misra_21_10(cfg)
16091630
misra_21_11(cfg)
16101631
# 22.4 is already covered by Cppcheck writeReadOnlyFile
16111632
if VERIFY:

addons/test/misra-test.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
#include /*abc*/ "file.h" // 20.3
66
#include <setjmp.h> // 21.4
77
#include <signal.h> // 21.5
8+
#include <stdio.h> //21.6
9+
#include <wchar.h> //21.6
10+
#include <time.h> // 21.10
811
#include <tgmath.h> // 21.11
912

13+
1014
typedef unsigned char u8;
1115
typedef unsigned short u16;
1216
typedef unsigned int u32;

0 commit comments

Comments
 (0)