misra.py: Fix R5.4 false positives with C99 (#2516)
* parser: Parse standards node at start event This required, because we can loose data at the end event. * misra.py: Fix 5.4 standard-dependent error By default Cppcheck use C11 standard, so this change fix false positives for rule 5.4 with C99. * travis: force --std=c89 for misra.py
This commit is contained in:
parent
fb38e87bf4
commit
5eaf437c44
|
@ -126,7 +126,9 @@ matrix:
|
||||||
- cd ../../
|
- cd ../../
|
||||||
# check addons/misra.py
|
# check addons/misra.py
|
||||||
- cd addons/test
|
- cd addons/test
|
||||||
- ${CPPCHECK} --dump misra/misra-test.c
|
# We'll force C89 standard to enable an additional verification for
|
||||||
|
# rules 5.4 and 5.5 which have standard-dependent options.
|
||||||
|
- ${CPPCHECK} --dump misra/misra-test.c --std=c89
|
||||||
- python3 ../misra.py -verify misra/misra-test.c.dump
|
- python3 ../misra.py -verify misra/misra-test.c.dump
|
||||||
- ${CPPCHECK} --dump misra/misra-test.cpp
|
- ${CPPCHECK} --dump misra/misra-test.cpp
|
||||||
- python3 ../misra.py -verify misra/misra-test.cpp.dump
|
- python3 ../misra.py -verify misra/misra-test.cpp.dump
|
||||||
|
|
|
@ -656,7 +656,7 @@ class Configuration:
|
||||||
functions = []
|
functions = []
|
||||||
variables = []
|
variables = []
|
||||||
valueflow = []
|
valueflow = []
|
||||||
standards = []
|
standards = None
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
@ -666,7 +666,7 @@ class Configuration:
|
||||||
self.functions = []
|
self.functions = []
|
||||||
self.variables = []
|
self.variables = []
|
||||||
self.valueflow = []
|
self.valueflow = []
|
||||||
self.standards = []
|
self.standards = Standards()
|
||||||
|
|
||||||
def set_tokens_links(self):
|
def set_tokens_links(self):
|
||||||
"""Set next/previous links between tokens."""
|
"""Set next/previous links between tokens."""
|
||||||
|
@ -762,10 +762,18 @@ class Standards:
|
||||||
posix If Posix was used
|
posix If Posix was used
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, standardsnode):
|
c = ""
|
||||||
self.c = standardsnode.find("c").get("version")
|
cpp = ""
|
||||||
self.cpp = standardsnode.find("cpp").get("version")
|
posix = False
|
||||||
self.posix = standardsnode.find("posix") is not None
|
|
||||||
|
def set_c(self, node):
|
||||||
|
self.c = node.get("version")
|
||||||
|
|
||||||
|
def set_cpp(self, node):
|
||||||
|
self.cpp = node.get("version")
|
||||||
|
|
||||||
|
def set_posix(self, node):
|
||||||
|
self.posix = node.get("posix") is not None
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
attrs = ["c", "cpp", "posix"]
|
attrs = ["c", "cpp", "posix"]
|
||||||
|
@ -896,11 +904,15 @@ class CppcheckData:
|
||||||
cfg = None
|
cfg = None
|
||||||
cfg_arguments = []
|
cfg_arguments = []
|
||||||
|
|
||||||
# Parse nested elemenets of configuration node
|
# Parse standards
|
||||||
elif node.tag == "standards" and event == 'start':
|
elif node.tag == "standards" and event == 'start':
|
||||||
continue
|
continue
|
||||||
elif node.tag == "standards" and event == 'end':
|
elif node.tag == 'c' and event == 'start':
|
||||||
cfg.standards = Standards(node)
|
cfg.standards.set_c(node)
|
||||||
|
elif node.tag == 'cpp' and event == 'start':
|
||||||
|
cfg.standards.set_cpp(node)
|
||||||
|
elif node.tag == 'posix' and event == 'start':
|
||||||
|
cfg.standards.set_posix(node)
|
||||||
|
|
||||||
# Parse directives list
|
# Parse directives list
|
||||||
elif node.tag == 'directive' and event == 'start':
|
elif node.tag == 'directive' and event == 'start':
|
||||||
|
|
|
@ -806,10 +806,10 @@ class MisraChecker:
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_num_significant_naming_chars(self, cfg):
|
def get_num_significant_naming_chars(self, cfg):
|
||||||
if cfg.standards and cfg.standards.c == "c99":
|
if cfg.standards and cfg.standards.c == "c89":
|
||||||
return 63
|
|
||||||
else:
|
|
||||||
return 31
|
return 31
|
||||||
|
else:
|
||||||
|
return 63
|
||||||
|
|
||||||
def misra_2_7(self, data):
|
def misra_2_7(self, data):
|
||||||
for func in data.functions:
|
for func in data.functions:
|
||||||
|
|
Loading…
Reference in New Issue