~ubuntu-branches/ubuntu/vivid/gzip/vivid

« back to all changes in this revision

Viewing changes to build-aux/useless-if-before-free

  • Committer: Steve Langasek
  • Date: 2012-06-29 02:07:40 UTC
  • mfrom: (4.1.9 sid)
  • Revision ID: steve.langasek@canonical.com-20120629020740-qqikrblzana08v2y
Merge version 1.5-1.1 from Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
  & eval 'exec perl -wST "$0" $argv:q'
3
3
    if 0;
4
4
# Detect instances of "if (p) free (p);".
5
 
# Likewise for "if (p != NULL) free (p);".  And with braces.
6
 
# Also detect "if (NULL != p) free (p);".
7
 
# And with 0 in place of NULL.
 
5
# Likewise "if (p != 0)", "if (0 != p)", or with NULL; and with braces.
8
6
 
9
 
my $VERSION = '2009-04-16 15:57'; # UTC
 
7
my $VERSION = '2012-01-06 07:23'; # UTC
10
8
# The definition above must lie within the first 8 lines in order
11
9
# for the Emacs time-stamp write hook (at end) to update it.
12
10
# If you change this file with Emacs, please let the write hook
13
11
# do its job.  Otherwise, update this string manually.
14
12
 
15
 
# Copyright (C) 2008-2010 Free Software Foundation, Inc.
 
13
# Copyright (C) 2008-2012 Free Software Foundation, Inc.
16
14
 
17
15
# This program is free software: you can redistribute it and/or modify
18
16
# it under the terms of the GNU General Public License as published by
49
47
  my $STREAM = ($exit_code == 0 ? *STDOUT : *STDERR);
50
48
  if ($exit_code != 0)
51
49
    {
52
 
      print $STREAM "Try `$ME --help' for more information.\n";
 
50
      print $STREAM "Try '$ME --help' for more information.\n";
53
51
    }
54
52
  else
55
53
    {
63
61
 
64
62
OPTIONS:
65
63
 
66
 
   --list       print only the name of each matching FILE (\0-terminated)
67
 
   --name=N     add name N to the list of \`free\'-like functions to detect;
 
64
   --list       print only the name of each matching FILE (\\0-terminated)
 
65
   --name=N     add name N to the list of \'free\'-like functions to detect;
68
66
                  may be repeated
69
67
 
70
68
   --help       display this help and exit
127
125
  foreach my $file (@ARGV)
128
126
    {
129
127
      open FH, '<', $file
130
 
        or (warn "$ME: can't open `$file' for reading: $!\n"),
 
128
        or (warn "$ME: can't open '$file' for reading: $!\n"),
131
129
          $err = EXIT_ERROR, next;
132
130
      while (defined (my $line = <FH>))
133
131
        {
134
132
          while ($line =~
135
133
              /\b(if\s*\(\s*([^)]+?)(?:\s*!=\s*([^)]+?))?\s*\)
136
134
              #  1          2                  3
137
 
               (?:   \s*$regexp\s*\((?:\s*\([^)]+\))?\s*([^)]+)\)|
 
135
               (?:   \s*$regexp\s*\((?:\s*\([^)]+\))?\s*([^)]+)\)\s*;|
138
136
                \s*\{\s*$regexp\s*\((?:\s*\([^)]+\))?\s*([^)]+)\)\s*;\s*\}))/sxg)
139
137
            {
140
138
              my $all = $1;
181
179
git grep -l -z "$free *(" \
182
180
  | xargs -0 useless-if-before-free -l --name="$free" \
183
181
  | xargs -0 perl -0x3b -pi -e \
184
 
   's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*(?:0|NULL))?\s*\)\s+('"$free"'\s*\((?:\s*\([^)]+\))?\s*\1\s*\))/$2/s'
 
182
   's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*(?:0|NULL))?\s*\)\s+('"$free"'\s*\((?:\s*\([^)]+\))?\s*\1\s*\)\s*;)/$2/s'
185
183
 
186
184
# Use the following to remove redundant uses of kfree inside braces.
187
185
# Note that -0777 puts perl in slurp-whole-file mode;