Skip to content

Commit d50823f

Browse files
committed
Fix misra crash when premium addon fails
1 parent 51b4cf5 commit d50823f

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

addons/cppcheckdata.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,3 +1386,10 @@ def get_path_premium_addon():
13861386
if os.path.isfile(p1) and os.path.isfile(p2):
13871387
return p1
13881388
return None
1389+
1390+
1391+
def cmd_output(cmd):
1392+
try:
1393+
return subprocess.check_output([self.path_premium_addon, '--cli', '--get-rule-text=' + errorId]).strip().decode('ascii')
1394+
except subprocess.CalledProcessError as e:
1395+
return e.output

addons/misra.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4060,13 +4060,11 @@ def reportError(self, location, num1, num2):
40604060
misra_severity = self.ruleTexts[ruleNum].misra_severity
40614061
cppcheck_severity = self.ruleTexts[ruleNum].cppcheck_severity
40624062
elif len(self.ruleTexts) == 0:
4063+
errmsg = 'misra violation (use --rule-texts=<file> to get proper output)'
40634064
if self.path_premium_addon:
4064-
errmsg = ''
4065-
for line in subprocess.check_output([self.path_premium_addon, '--cli', '--get-rule-text=' + errorId]).strip().decode('ascii').split('\n'):
4065+
for line in cppcheckdata.cmd_output([self.path_premium_addon, '--cli', '--get-rule-text=' + errorId]).split('\n'):
40664066
if not line.startswith('{'):
40674067
errmsg = line
4068-
else:
4069-
errmsg = 'misra violation (use --rule-texts=<file> to get proper output)'
40704068
else:
40714069
errmsg = 'misra violation %s with no text in the supplied rule-texts-file' % (ruleNum)
40724070

@@ -4402,7 +4400,7 @@ def fillVerifyExpected(verify_expected, tok):
44024400

44034401
# Premium MISRA checking, deep analysis
44044402
if cfgNumber == 0 and self.path_premium_addon:
4405-
subprocess.check_output([self.path_premium_addon, '--cli', '--misra', dumpfile])
4403+
subprocess.cmd_output([self.path_premium_addon, '--cli', '--misra', dumpfile])
44064404

44074405
def analyse_ctu_info(self, ctu_info_files):
44084406
all_typedef_info = []
@@ -4667,7 +4665,7 @@ def main():
46674665
premium_command = [checker.path_premium_addon, '--misra', '--file-list', args.file_list]
46684666
if args.cli:
46694667
premium_command.append('--cli')
4670-
for line in subprocess.check_output(premium_command).decode('ascii').split('\n'):
4668+
for line in subprocess.cmd_output(premium_command).split('\n'):
46714669
if re.search(r'"errorId".*:.*"misra-', line) is not None:
46724670
print(line.strip())
46734671

0 commit comments

Comments
 (0)