From: Nicholas Nethercote Date: Sun, 5 Dec 2021 21:09:29 +0000 (+1100) Subject: Fix `cg_annotate` warnings when using `cg_diff`. X-Git-Tag: VALGRIND_3_19_0~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8e60cde69e879627e872668b084f1672195990a0;p=thirdparty%2Fvalgrind.git 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 --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 = ; - 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 = )) { - 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 = ; + 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 = )) { + 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; } }