@@ -538,6 +538,20 @@ def is_source_file(file):
538538 return file .endswith ('.c' )
539539
540540
541+ def has_prior_function_prototype (cfg , function ):
542+ """Return whether a global prototype precedes the function definition."""
543+ for token in cfg .tokenlist :
544+ if token == function .tokenDef :
545+ break
546+ if token .str != function .name or token .scope .type != 'Global' :
547+ continue
548+ opening = token .next
549+ if opening and opening .str == '(' and opening .link and \
550+ opening .link .next and opening .link .next .str == ';' :
551+ return True
552+ return False
553+
554+
541555def is_header (file ):
542556 return file .endswith ('.h' )
543557
@@ -803,7 +817,8 @@ def get_function_pointer_type(tok):
803817 ret += '('
804818 tok = tok .next .next
805819 while tok and (tok .str not in '()' ):
806- ret += ' ' + tok .str
820+ if tok .varId is None :
821+ ret += ' ' + tok .str
807822 tok = tok .next
808823 if (tok is None ) or tok .str != ')' :
809824 return None
@@ -2248,6 +2263,8 @@ def misra_8_4(self, cfg):
22482263 continue
22492264 if func .token != func .tokenDef :
22502265 continue
2266+ if has_prior_function_prototype (cfg , func ):
2267+ continue
22512268 if func .tokenDef .str == 'main' :
22522269 continue
22532270 self .reportError (func .tokenDef , 8 , 4 )
@@ -3497,8 +3514,9 @@ def misra_17_3(self, cfg):
34973514
34983515 # Additional check for implicit function calls in expressions
34993516 for token in cfg .tokenlist :
3500- if token .isName and token .function is None and token .valueType is None :
3501- if token .next and token .next .str == "(" and token .next .valueType is None :
3517+ if token .isName and token .scope .type != 'Global' and token .function is None and token .valueType is None :
3518+ if token .next and token .next .str == "(" and token .next .valueType is None and \
3519+ isFunctionCall (token .next , cfg .standards .c ):
35023520 if token .next .next .str == "*" and \
35033521 token .next .next .next .isName and token .next .next .next .valueType is not None and \
35043522 token .next .next .next .valueType .pointer > 0 :
0 commit comments