]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix `cg_annotate` warnings when using `cg_diff`.
authorNicholas Nethercote <n.nethercote@gmail.com>
Sun, 5 Dec 2021 21:09:29 +0000 (08:09 +1100)
committerNicholas Nethercote <n.nethercote@gmail.com>
Sun, 5 Dec 2021 21:12:34 +0000 (08:12 +1100)
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.

cachegrind/cg_annotate.in

index fea114bf49e76ae0268e56b30b3632fb39fe086f..9111fbe7efa95c39980e9c9c623283fa9c60447b 100644 (file)
@@ -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;
                 }
             }