]> sourceware.org Git - valgrind.git/commitdiff
cg_annotate.in: fix a small bug in the printing of past-the-end lines.
authorNicholas Nethercote <n.nethercote@gmail.com>
Tue, 28 Mar 2023 06:22:42 +0000 (17:22 +1100)
committerNicholas Nethercote <n.nethercote@gmail.com>
Tue, 28 Mar 2023 06:22:42 +0000 (17:22 +1100)
cachegrind/cg_annotate.in
cachegrind/tests/ann2.post.exp

index 240e069ccb5a707c60beadea314a9b1c062f7345..2ebd93911b15b9df9111322e6993e320656e7473 100755 (executable)
@@ -686,18 +686,17 @@ def print_annotated_src_file(
         pairs.append((lo, hi))
         i += 1
 
-    # Annotate chosen lines, tracking total annotated counts.
-    line_num = 0
-    if pairs:
+    def print_lines(pairs: list[tuple[int, int]]) -> None:
+        line_num = 0
         while pairs:
+            src_line = ""
             (lo, hi) = pairs.pop(0)
             while line_num < lo - 1:
-                tmp = src_file.readline()
+                src_line = src_file.readline()
                 line_num += 1
-                if not tmp:
-                    break  # EOF
+                if not src_line:
+                    return  # EOF
 
-            src_line = ""
             # Print line number, unless start of file.
             if lo != 1:
                 print("-- line", lo, "-" * 40)
@@ -706,7 +705,7 @@ def print_annotated_src_file(
                 src_line = src_file.readline()
                 line_num += 1
                 if not src_line:
-                    break
+                    return  # EOF
                 if line_nums and line_num == line_nums[0]:
                     printer.print_cc(dict_line_cc[line_num], src_line[:-1])
                     annotated_ccs.line_nums_known_cc += dict_line_cc[line_num]
@@ -714,14 +713,16 @@ def print_annotated_src_file(
                 else:
                     printer.print_missing_cc(src_line[:-1])
 
-            # Print line number, unless EOF.
-            if src_line:
-                print("-- line", hi, "-" * 40)
-            else:
-                break
+            # Print line number.
+            print("-- line", hi, "-" * 40)
+
+    # Annotate chosen lines, tracking total annotated counts.
+    if pairs:
+        print_lines(pairs)
 
         # If there was info on lines past the end of the file, warn.
         if line_nums:
+            print()
             for line_num in line_nums:
                 printer.print_cc(dict_line_cc[line_num], f"<bogus line {line_num}>")
                 annotated_ccs.line_nums_known_cc += dict_line_cc[line_num]
index 315e13474de70d732b81afc99d1382cbe0024b40..0e85dcb556c5ad028248dc4fdb0f2ce914fc678d 100644 (file)
@@ -126,7 +126,7 @@ A          SomeCount        VeryLongEventName
   .                .                        .        two
   .                .                        .        three
 -- line 3 ----------------------------------------
--- line 18 ----------------------------------------
+
 300 (0.3%)       100 (0.1%)                 0        <bogus line 20>
 300 (0.3%)       100 (0.1%)                 0        <bogus line 21>
 200 (0.2%)         0                   -1,000 (n/a)  <bogus line 22>
This page took 0.036943 seconds and 5 git commands to generate.