Skip to content

Commit cf6f2e6

Browse files
Peter Oberparleiteroberpar
authored andcommitted
geninfo: Tolerate garbage at end of gcno file
Some versions of gcc produce garbage at the end of a gcno file when recompiling a source code file after removing some lines. This patch makes geninfo's gcno file parser more robust by assuming end-of-file when it finds a record that extends beyond the end-of-file. Signed-off-by: Peter Oberparleiter <[email protected]>
1 parent 14286b2 commit cf6f2e6

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

bin/geninfo

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ if( $^O eq "msys" )
6161
}
6262

6363
# Constants
64-
our $lcov_version = 'LCOV version 1.11 pre (CVS $Revision: 1.125 $)';
64+
our $lcov_version = 'LCOV version 1.11 pre (CVS $Revision: 1.126 $)';
6565
our $lcov_url = "http://ltp.sourceforge.net/coverage/lcov.php";
6666
our $gcov_tool = "gcov";
6767
our $tool_name = basename($0);
@@ -3384,9 +3384,11 @@ sub read_gcno($)
33843384
my $fileorder = {};
33853385
my $instr;
33863386
my $graph;
3387+
my $filelength;
33873388
local *HANDLE;
33883389

33893390
open(HANDLE, "<", $gcno_filename) or goto open_error;
3391+
$filelength = (stat(HANDLE))[7];
33903392
binmode(HANDLE);
33913393
# Read magic
33923394
$word = read_gcno_word(*HANDLE, "file magic");
@@ -3418,6 +3420,14 @@ sub read_gcno($)
34183420
$next_pos = tell(HANDLE);
34193421
goto tell_error if ($next_pos == -1);
34203422
$next_pos += $length;
3423+
# Catch garbage at the end of a gcno file
3424+
if ($next_pos > $filelength) {
3425+
debug("Overlong record: file_length=$filelength ".
3426+
"rec_length=$length\n");
3427+
warn("WARNING: $gcno_filename: Overlong record at end ".
3428+
"of file!\n");
3429+
last;
3430+
}
34213431
# Process record
34223432
if ($tag == $tag_function) {
34233433
($filename, $function) = read_gcno_function_record(

0 commit comments

Comments
 (0)