@@ -3259,23 +3259,26 @@ def misra_17_3(self, cfg):
32593259
32603260 def misra_config (self , data ):
32613261 for token in data .tokenlist :
3262- if token .str not in ["while" , "if" ]:
3263- continue
3264- if token .next .str != "(" :
3262+ if token .str not in ("while" , "if" ):
32653263 continue
32663264 tok = token .next
3267- while tok != token .next .link :
3265+ if token is None or tok .str != "(" :
3266+ continue
3267+ end_token = tok .link
3268+ while tok != end_token :
3269+ tok = tok .next
32683270 if tok .str == "(" and tok .isCast :
32693271 tok = tok .link
32703272 continue
3271- if not tok .isName or tok .function or tok .variable or tok .varId or tok .valueType \
3272- or tok .next .str == "(" or tok .str in ["EOF" ] \
3273- or isKeyword (tok .str ) or isStdLibId (tok .str ):
3274- tok = tok .next
3273+ if not tok .isName :
32753274 continue
3276- errmsg = tok .str + " Variable is unknown"
3277- self .reportError (token , 0 , 0 , "config" )
3278- break
3275+ if tok .function or tok .variable or tok .varId or tok .valueType :
3276+ continue
3277+ if tok .next .str == "(" or tok .str in ["EOF" ]:
3278+ continue
3279+ if isKeyword (tok .str ) or isStdLibId (tok .str ):
3280+ continue
3281+ self .report_config_error (tok , "Variable '%s' is unknown" % tok .str )
32793282
32803283 def misra_17_6 (self , rawTokens ):
32813284 for token in rawTokens :
@@ -4184,30 +4187,29 @@ def setSuppressionList(self, suppressionlist):
41844187
41854188 self .addSuppressedRule (ruleNum )
41864189
4187- def reportError (self , location , num1 , num2 , other_id = None ):
4188- if not other_id :
4189- ruleNum = num1 * 100 + num2
4190+ def report_config_error (self , location , errmsg ):
4191+ cppcheck_severity = 'error'
4192+ error_id = 'config'
4193+ if self .settings .verify :
4194+ self .verify_actual .append ('%s:%d %s' % (location .file , location .linenr , error_id ))
41904195 else :
4191- ruleNum = other_id
4196+ cppcheckdata .reportError (location , cppcheck_severity , errmsg , 'misra' , error_id )
4197+
4198+ def reportError (self , location , num1 , num2 ):
4199+ ruleNum = num1 * 100 + num2
41924200
41934201 if self .isRuleGloballySuppressed (ruleNum ):
41944202 return
41954203
41964204 if self .settings .verify :
4197- if not other_id :
4198- self .verify_actual .append ('%s:%d %d.%d' % (location .file , location .linenr , num1 , num2 ))
4199- else :
4200- self .verify_actual .append ('%s:%d %s' % (location .file , location .linenr , other_id ))
4205+ self .verify_actual .append ('%s:%d %d.%d' % (location .file , location .linenr , num1 , num2 ))
42014206 elif self .isRuleSuppressed (location .file , location .linenr , ruleNum ):
42024207 # Error is suppressed. Ignore
42034208 self .suppressionStats .setdefault (ruleNum , 0 )
42044209 self .suppressionStats [ruleNum ] += 1
42054210 return
42064211 else :
4207- if not other_id :
4208- errorId = 'c2012-' + str (num1 ) + '.' + str (num2 )
4209- else :
4210- errorId = 'c2012-' + other_id
4212+ errorId = 'c2012-' + str (num1 ) + '.' + str (num2 )
42114213 misra_severity = 'Undefined'
42124214 cppcheck_severity = 'style'
42134215 if ruleNum in self .ruleTexts :
0 commit comments