@@ -2460,27 +2460,38 @@ def get_category(essential_type):
24602460 if essential_type .split (' ' )[0 ] in ('unsigned' , 'signed' ):
24612461 return essential_type .split (' ' )[0 ]
24622462 return None
2463+
24632464 for tok in cfg .tokenlist :
2464- if tok .isAssignmentOp :
2465- lhs = getEssentialType (tok .astOperand1 )
2466- rhs = getEssentialType (tok .astOperand2 )
2467- #print(lhs)
2468- #print(rhs)
2469- if lhs is None or rhs is None :
2465+ if not tok .isAssignmentOp :
2466+ continue
2467+
2468+ lhs = getEssentialType (tok .astOperand1 )
2469+ rhs = getEssentialType (tok .astOperand2 )
2470+ if lhs is None or rhs is None :
2471+ continue
2472+
2473+ find_std = cfg .standards .c if cfg .standards and cfg .standards .c else self .stdversion
2474+
2475+ rhs_tok = tok .astOperand2
2476+ rhs_macro_name = rhs_tok .macroName if rhs_tok else None
2477+ rhs_spelling = rhs_macro_name if rhs_macro_name in ('true' , 'false' ) else rhs_tok .str
2478+
2479+ rhs_is_source_bool_literal = rhs_spelling in ('true' , 'false' )
2480+ rhs_is_source_int_literal_0_1 = rhs_spelling in ('0' , '1' )
2481+
2482+ if lhs == 'bool' :
2483+ if rhs_is_source_bool_literal :
2484+ continue
2485+ if find_std == 'c89' and rhs_is_source_int_literal_0_1 :
24702486 continue
2471- lhs_category = get_category (lhs )
2472- rhs_category = get_category (rhs )
2473- if lhs_category and rhs_category and lhs_category != rhs_category and rhs_category not in ('signed' ,'unsigned' ):
2474- self .reportError (tok , 10 , 3 )
2475- find_std = cfg .standards .c if cfg .standards and cfg .standards .c else self .stdversion
2476- allow_bool_literal_0_1 = (
2477- find_std == "c89" and
2478- lhs == "bool" and
2479- tok .astOperand2 and
2480- tok .astOperand2 .str in ('0' , '1' )
2481- )
2482- if bitsOfEssentialType (lhs ) < bitsOfEssentialType (rhs ) and not allow_bool_literal_0_1 :
2483- self .reportError (tok , 10 , 3 )
2487+
2488+ lhs_category = get_category (lhs )
2489+ rhs_category = get_category (rhs )
2490+ if lhs_category and rhs_category and lhs_category != rhs_category and rhs_category not in ('signed' , 'unsigned' ):
2491+ self .reportError (tok , 10 , 3 )
2492+
2493+ if bitsOfEssentialType (lhs ) < bitsOfEssentialType (rhs ):
2494+ self .reportError (tok , 10 , 3 )
24842495
24852496 def misra_10_4 (self , data ):
24862497 op = {'+' , '-' , '*' , '/' , '%' , '&' , '|' , '^' , '+=' , '-=' , ':' }
0 commit comments