1616# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
1717# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
1818# changes)
19- CLIENT_VERSION = "1.4.1 "
19+ CLIENT_VERSION = "1.4.2 "
2020
2121# Timeout for analysis with Cppcheck in seconds
2222CPPCHECK_TIMEOUT = 30 * 60
@@ -437,6 +437,20 @@ def __run_command(cmd, print_cmd=True):
437437 return return_code , stdout , stderr , elapsed_time
438438
439439
440+ # glibc assertion failure message: "<program>: <file>:<line>: <function>: Assertion `<expression>' failed."
441+ # Example: cppcheck: lib/token.cpp:123: void Token::foo(): Assertion `x' failed.
442+ __assertion_failure_re = re .compile (r"^\S+: [^:\s]+:\d+: .+: Assertion `.+' failed\.$" )
443+
444+
445+ def get_assertion_failures (text ):
446+ messages = []
447+ for line in text .split ('\n ' ):
448+ line = line .strip ()
449+ if __assertion_failure_re .match (line ) and line not in messages :
450+ messages .append (line )
451+ return messages
452+
453+
440454def scan_package (cppcheck_path , source_path , libraries , capture_callstack = True , enable = 'style,information' , debug_warnings = True , check_level = None , extra_args = None ):
441455 print ('Analyze..' )
442456 libs = ''
@@ -536,6 +550,7 @@ def scan_package(cppcheck_path, source_path, libraries, capture_callstack=True,
536550 # make sure we have the actual error code set
537551 if has_sig :
538552 returncode = - sig_num
553+ assertion_failures = get_assertion_failures (stderr )
539554 stacktrace = ''
540555 if capture_callstack :
541556 # re-run within gdb to get a stacktrace
@@ -544,20 +559,33 @@ def scan_package(cppcheck_path, source_path, libraries, capture_callstack=True,
544559 cmd += sig_file
545560 else :
546561 cmd += dir_to_scan
547- _ , st_stdout , _ , _ = __run_command (cmd )
562+ _ , st_stdout , st_stderr , _ = __run_command (cmd )
563+ for msg in get_assertion_failures (st_stderr ):
564+ if msg not in assertion_failures :
565+ assertion_failures .append (msg )
548566 gdb_pos = st_stdout .find (" received signal" )
549567 if gdb_pos != - 1 :
550568 last_check_pos = st_stdout .rfind ('Checking ' , 0 , gdb_pos )
551569 if last_check_pos == - 1 :
552570 stacktrace = st_stdout [gdb_pos :]
553571 else :
554- stacktrace = st_stdout [last_check_pos :]
572+ # put the assertion failure messages before the ' received signal ' line, the servers parse the stack trace after that line
573+ signal_line_pos = st_stdout .rfind ('\n ' , 0 , gdb_pos ) + 1
574+ if signal_line_pos < last_check_pos :
575+ signal_line_pos = last_check_pos
576+ stacktrace = st_stdout [last_check_pos :signal_line_pos ] + \
577+ '' .join (msg + '\n ' for msg in assertion_failures ) + \
578+ st_stdout [signal_line_pos :]
579+ assertion_failures = []
555580 # if no stacktrace was generated return the original stdout or internal errors list
556581 if not stacktrace :
557582 if has_sig :
558583 stacktrace = '' .join (internal_error_messages_list )
559584 else :
560585 stacktrace = stdout
586+ # assertion failure messages that were not put in the gdb output
587+ if assertion_failures :
588+ stacktrace = '' .join (msg + '\n ' for msg in assertion_failures ) + stacktrace
561589 return returncode , stacktrace , '' , returncode , options_j , ''
562590
563591 if returncode != 0 :
0 commit comments