|
From: Nicholas N. <nj...@so...> - 2021-12-05 21:57:53
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=8e60cde69e879627e872668b084f1672195990a0 commit 8e60cde69e879627e872668b084f1672195990a0 Author: Nicholas Nethercote <n.n...@gm...> Date: Mon Dec 6 08:09:29 2021 +1100 Fix `cg_annotate` warnings when using `cg_diff`. When running `cg_annotate` on files produced with `cg_diff`, it's common to get multiple occurrences of this pair of errors: ``` Use of uninitialized value $pairs[0] in numeric lt (<) at /home/njn/grind/ws1/cachegrind/cg_annotate line 848. Use of uninitialized value $high in numeric lt (<) at /home/njn/grind/ws1/cachegrind/cg_annotate line 859. ``` This is because `cg_annotate` wasn't properly handling the case where no source code lines have annotations, which never happens in the normal case but does happen in `cg_diff` output. Happily, it turns out that the warnings were harmless, the fix is trivial, and it doesn't change the output at all. Diff: --- cachegrind/cg_annotate.in | 56 ++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/cachegrind/cg_annotate.in b/cachegrind/cg_annotate.in index fea114bf49..9111fbe7ef 100644 --- a/cachegrind/cg_annotate.in +++ b/cachegrind/cg_annotate.in @@ -845,35 +845,37 @@ sub annotate_ann_files($) } # Annotate chosen lines, tracking total counts of lines printed - $pairs[0] = 1 if ($pairs[0] < 1); - while (@pairs) { - my $low = shift @pairs; - my $high = shift @pairs; - while ($. < $low-1) { - my $tmp = <INPUTFILE>; - last unless (defined $tmp); # hack to detect EOF - } - my $src_line; - # Print line number, unless start of file - print("-- line $low " . '-' x 40 . "\n") if ($low != 1); - while (($. < $high) && ($src_line = <INPUTFILE>)) { - if (defined $line_nums[0] && $. == $line_nums[0]) { - print_CC($src_file_CCs->{$.}, $CC_col_widths); - add_array_a_to_b($src_file_CCs->{$.}, - $printed_totals_CC); - shift(@line_nums); - + if (@pairs) { + $pairs[0] = 1 if ($pairs[0] < 1); + while (@pairs) { + my $low = shift @pairs; + my $high = shift @pairs; + while ($. < $low-1) { + my $tmp = <INPUTFILE>; + last unless (defined $tmp); # hack to detect EOF + } + my $src_line; + # Print line number, unless start of file + print("-- line $low " . '-' x 40 . "\n") if ($low != 1); + while (($. < $high) && ($src_line = <INPUTFILE>)) { + if (defined $line_nums[0] && $. == $line_nums[0]) { + print_CC($src_file_CCs->{$.}, $CC_col_widths); + add_array_a_to_b($src_file_CCs->{$.}, + $printed_totals_CC); + shift(@line_nums); + + } else { + print_CC([], $CC_col_widths); + } + + print(" $src_line"); + } + # Print line number, unless EOF + if ($src_line) { + print("-- line $high " . '-' x 40 . "\n"); } else { - print_CC([], $CC_col_widths); + last; } - - print(" $src_line"); - } - # Print line number, unless EOF - if ($src_line) { - print("-- line $high " . '-' x 40 . "\n"); - } else { - last; } } |