(self, data)
| 2066 | self.reportError(tok, 7, 3) |
| 2067 | |
| 2068 | def misra_7_4(self, data): |
| 2069 | # A string literal shall not be assigned to an object unless the object's type |
| 2070 | # is constant. |
| 2071 | def reportErrorIfVariableIsNotConst(variable, stringLiteral): |
| 2072 | if variable.valueType: |
| 2073 | if (variable.valueType.constness % 2) != 1: |
| 2074 | self.reportError(stringLiteral, 7, 4) |
| 2075 | |
| 2076 | for token in data.tokenlist: |
| 2077 | if token.isString: |
| 2078 | # Check normal variable assignment |
| 2079 | variable = getAssignedVariableToken(token) |
| 2080 | if variable: |
| 2081 | reportErrorIfVariableIsNotConst(variable, token) |
| 2082 | |
| 2083 | # Check use as return value |
| 2084 | function = getFunctionUsingReturnValue(token) |
| 2085 | if function: |
| 2086 | # "Primitive" test since there is no info available on return value type |
| 2087 | if not tokenFollowsSequence(function.tokenDef, ['const', 'char', '*']): |
| 2088 | self.reportError(token, 7, 4) |
| 2089 | |
| 2090 | # Check use as function parameter |
| 2091 | if isFunctionCall(token, data.standards.c) and token.astOperand1 and token.astOperand1.function: |
| 2092 | functionDeclaration = token.astOperand1.function |
| 2093 | |
| 2094 | if functionDeclaration.tokenDef: |
| 2095 | if functionDeclaration.tokenDef is token.astOperand1: |
| 2096 | # Token is not a function call, but it is the definition of the function |
| 2097 | continue |
| 2098 | |
| 2099 | parametersUsed = getArguments(token) |
| 2100 | for i in range(len(parametersUsed)): |
| 2101 | usedParameter = parametersUsed[i] |
| 2102 | parameterDefinition = functionDeclaration.argument.get(i+1) |
| 2103 | |
| 2104 | if usedParameter.isString and parameterDefinition and parameterDefinition.nameToken: |
| 2105 | reportErrorIfVariableIsNotConst(parameterDefinition.nameToken, usedParameter) |
| 2106 | |
| 2107 | def misra_8_1(self, cfg): |
| 2108 | for token in cfg.tokenlist: |
nothing calls this directly
no test coverage detected