MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / misra_10_3

Method misra_10_3

addons/misra.py:2452–2493  ·  view source on GitHub ↗
(self, cfg)

Source from the content-addressed store, hash-verified

2450 self.reportError(token, 10, 2)
2451
2452 def misra_10_3(self, cfg):
2453 def get_category(essential_type):
2454 if essential_type:
2455 if essential_type in ('bool', 'char'):
2456 return essential_type
2457 if essential_type.split(' ')[-1] in ('float', 'double'):
2458 return 'floating'
2459 if essential_type.split(' ')[0] in ('unsigned', 'signed'):
2460 return essential_type.split(' ')[0]
2461 return None
2462
2463 for tok in cfg.tokenlist:
2464 if not tok.isAssignmentOp:
2465 continue
2466
2467 lhs = getEssentialType(tok.astOperand1)
2468 rhs = getEssentialType(tok.astOperand2)
2469 if lhs is None or rhs is None:
2470 continue
2471
2472 find_std = cfg.standards.c if cfg.standards and cfg.standards.c else self.stdversion
2473
2474 rhs_tok = tok.astOperand2
2475 rhs_macro_name = rhs_tok.macroName if rhs_tok else None
2476 rhs_spelling = rhs_macro_name if rhs_macro_name in ('true', 'false') else rhs_tok.str
2477
2478 rhs_is_source_bool_literal = rhs_spelling in ('true', 'false')
2479 rhs_is_source_int_literal_0_1 = rhs_spelling in ('0', '1')
2480
2481 if lhs == 'bool':
2482 if rhs_is_source_bool_literal:
2483 continue
2484 if find_std == 'c89' and rhs_is_source_int_literal_0_1:
2485 continue
2486
2487 lhs_category = get_category(lhs)
2488 rhs_category = get_category(rhs)
2489 if lhs_category and rhs_category and lhs_category != rhs_category and rhs_category not in ('signed', 'unsigned'):
2490 self.reportError(tok, 10, 3)
2491
2492 if bitsOfEssentialType(lhs) < bitsOfEssentialType(rhs):
2493 self.reportError(tok, 10, 3)
2494
2495 def misra_10_4(self, data):
2496 op = {'+', '-', '*', '/', '%', '&', '|', '^', '+=', '-=', ':'}

Callers

nothing calls this directly

Calls 3

reportErrorMethod · 0.95
getEssentialTypeFunction · 0.85
bitsOfEssentialTypeFunction · 0.85

Tested by

no test coverage detected