misra: fix crash
This commit is contained in:
parent
d7317b4f8a
commit
8dbc1b802a
|
@ -158,6 +158,11 @@ jobs:
|
||||||
../../cppcheck --dump -DDUMMY --suppress=uninitvar --inline-suppr misra/misra-test.c --std=c89 --platform=unix64 && python3 ../misra.py -verify misra/misra-test.c.dump
|
../../cppcheck --dump -DDUMMY --suppress=uninitvar --inline-suppr misra/misra-test.c --std=c89 --platform=unix64 && python3 ../misra.py -verify misra/misra-test.c.dump
|
||||||
../../cppcheck --addon=misra --platform=avr8 --error-exitcode=1 misra/misra-test-avr8.c
|
../../cppcheck --addon=misra --platform=avr8 --error-exitcode=1 misra/misra-test-avr8.c
|
||||||
|
|
||||||
|
- name: Ensure misra addon does not crash
|
||||||
|
if: contains(matrix.os, 'ubuntu')
|
||||||
|
run: |
|
||||||
|
./cppcheck --addon=misra addons/test/misra/crash1.c | ( ! grep 'Bailing out from checking' )
|
||||||
|
|
||||||
- name: Build GUI on ubuntu
|
- name: Build GUI on ubuntu
|
||||||
if: contains(matrix.os, 'ubuntu')
|
if: contains(matrix.os, 'ubuntu')
|
||||||
run: |
|
run: |
|
||||||
|
|
|
@ -86,7 +86,7 @@ class ElementDef:
|
||||||
def getChildByIndex(self, index):
|
def getChildByIndex(self, index):
|
||||||
if self.isFlexible:
|
if self.isFlexible:
|
||||||
while len(self.children) <= index:
|
while len(self.children) <= index:
|
||||||
createChild(self, self.flexibleToken, len(self.children))
|
createChild(self, self.flexibleToken, len(self.children), None)
|
||||||
return self.children[index] if 0 <= index < len(self.children) else None
|
return self.children[index] if 0 <= index < len(self.children) else None
|
||||||
|
|
||||||
def getChildByName(self, name):
|
def getChildByName(self, name):
|
||||||
|
@ -384,7 +384,7 @@ def misra_9_x(self, data, rule, rawTokens = None):
|
||||||
parser = InitializerParser()
|
parser = InitializerParser()
|
||||||
|
|
||||||
for variable in data.variables:
|
for variable in data.variables:
|
||||||
if not variable.nameToken:
|
if variable.nameToken is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
nameToken = variable.nameToken
|
nameToken = variable.nameToken
|
||||||
|
@ -425,15 +425,15 @@ def misra_9_x(self, data, rule, rawTokens = None):
|
||||||
def getElementDef(nameToken, rawTokens = None):
|
def getElementDef(nameToken, rawTokens = None):
|
||||||
if nameToken.variable.isArray:
|
if nameToken.variable.isArray:
|
||||||
ed = ElementDef("array", nameToken.str, nameToken.valueType)
|
ed = ElementDef("array", nameToken.str, nameToken.valueType)
|
||||||
createArrayChildrenDefs(ed, nameToken.astParent, rawTokens)
|
createArrayChildrenDefs(ed, nameToken.astParent, nameToken.variable, rawTokens)
|
||||||
elif nameToken.variable.isClass:
|
elif nameToken.variable.isClass:
|
||||||
ed = ElementDef("record", nameToken.str, nameToken.valueType)
|
ed = ElementDef("record", nameToken.str, nameToken.valueType)
|
||||||
createRecordChildrenDefs(ed)
|
createRecordChildrenDefs(ed, nameToken.variable)
|
||||||
else:
|
else:
|
||||||
ed = ElementDef("value", nameToken.str, nameToken.valueType)
|
ed = ElementDef("value", nameToken.str, nameToken.valueType)
|
||||||
return ed
|
return ed
|
||||||
|
|
||||||
def createArrayChildrenDefs(ed, token, rawTokens = None):
|
def createArrayChildrenDefs(ed, token, var, rawTokens = None):
|
||||||
if token.str == '[':
|
if token.str == '[':
|
||||||
if rawTokens is not None:
|
if rawTokens is not None:
|
||||||
foundToken = next((rawToken for rawToken in rawTokens
|
foundToken = next((rawToken for rawToken in rawTokens
|
||||||
|
@ -447,30 +447,32 @@ def createArrayChildrenDefs(ed, token, rawTokens = None):
|
||||||
|
|
||||||
if (token.astOperand2 is not None) and (token.astOperand2.getKnownIntValue() is not None):
|
if (token.astOperand2 is not None) and (token.astOperand2.getKnownIntValue() is not None):
|
||||||
for i in range(token.astOperand2.getKnownIntValue()):
|
for i in range(token.astOperand2.getKnownIntValue()):
|
||||||
createChild(ed, token, i)
|
createChild(ed, token, i, var)
|
||||||
else:
|
else:
|
||||||
ed.markAsFlexibleArray(token)
|
ed.markAsFlexibleArray(token)
|
||||||
|
|
||||||
|
|
||||||
def createChild(ed, token, name):
|
def createChild(ed, token, name, var):
|
||||||
if token.astParent and token.astParent.str == '[':
|
if token.astParent and token.astParent.str == '[':
|
||||||
child = ElementDef("array", name, ed.valueType)
|
child = ElementDef("array", name, ed.valueType)
|
||||||
createArrayChildrenDefs(child, token.astParent)
|
createArrayChildrenDefs(child, token.astParent, var)
|
||||||
else:
|
else:
|
||||||
if ed.valueType and ed.valueType.type == "record":
|
if ed.valueType and ed.valueType.type == "record":
|
||||||
child = ElementDef("record", name, ed.valueType)
|
child = ElementDef("record", name, ed.valueType)
|
||||||
createRecordChildrenDefs(child)
|
createRecordChildrenDefs(child, var)
|
||||||
else:
|
else:
|
||||||
child = ElementDef("value", name, ed.valueType)
|
child = ElementDef("value", name, ed.valueType)
|
||||||
|
|
||||||
ed.addChild(child)
|
ed.addChild(child)
|
||||||
|
|
||||||
def createRecordChildrenDefs(ed):
|
def createRecordChildrenDefs(ed, var):
|
||||||
valueType = ed.valueType
|
valueType = ed.valueType
|
||||||
if not valueType or not valueType.typeScope:
|
if not valueType or not valueType.typeScope:
|
||||||
return
|
return
|
||||||
|
|
||||||
for variable in valueType.typeScope.varlist:
|
for variable in valueType.typeScope.varlist:
|
||||||
|
if variable is var:
|
||||||
|
continue
|
||||||
child = getElementDef(variable.nameToken)
|
child = getElementDef(variable.nameToken)
|
||||||
ed.addChild(child)
|
ed.addChild(child)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
|
||||||
|
struct expression {
|
||||||
|
int nargs;
|
||||||
|
struct expression *args[3];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct expression plvar = {0};
|
||||||
|
|
Loading…
Reference in New Issue