[PATCH] Print line numbers in unnecessary-if-before-free check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The unnecessary-if-before-free doesn't currently print line
numbers, which is a little annoying.

This patch fixes that with some rather hideous perl hacking.
I should have known to let well enough alone rather than
dredge up my long forgotten perl knowledge :-)

Signed-off-by: Mark McLoughlin <markmc@xxxxxxxxxx>

Index: libvirt/build-aux/find-unnecessary-if-before-free
===================================================================
--- libvirt.orig/build-aux/find-unnecessary-if-before-free	2008-02-07 09:24:08.000000000 +0000
+++ libvirt/build-aux/find-unnecessary-if-before-free	2008-02-07 09:29:16.000000000 +0000
@@ -18,15 +18,20 @@
     {
       open FH, '<', $file
 	or die "$ME: can't open `$file' for reading: $!\n";
+      my $i = 1;
       while (defined (my $line = <FH>))
 	{
-	  if ($line =~
+	  my @matches = ($line =~
 	      /\b(if\s*\(\s*(\S+?)(?:\s*!=\s*NULL)?\s*\)
-	       \s+(?:xmlXPathFreeContext|(?:sexpr_)?free)\s*\(\s*\2\s*\))/sx)
+	       \s+(?:xmlXPathFreeContext|(?:sexpr_)?free)\s*\(\s*\2\s*\))/sx);
+
+	  if (@matches)
 	    {
-	      print "$file: $1\n";
+	      my $j = $i + (my @a = split(/\n/, substr($line, 0, index($line, $matches[0])))) - 1;
+	      print "$file:$j $1\n";
 	      $found_match = 1;
 	    }
+          $i += (my @a = split(/\n/, $line)) - 1;
 	}
       close FH;
     }

-- 

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]