Improved var-checker and tweaked all the issues it found.
authorWayne Davison <wayned@samba.org>
Mon, 21 Jul 2008 07:10:22 +0000 (00:10 -0700)
committerWayne Davison <wayned@samba.org>
Mon, 21 Jul 2008 07:10:22 +0000 (00:10 -0700)
checksum.c
clientserver.c
io.c
log.c
main.c
options.c
packaging/var-checker
t_unsafe.c

index a5c0a43..9b6ec85 100644 (file)
@@ -24,8 +24,6 @@
 extern int checksum_seed;
 extern int protocol_version;
 
-int csum_length = SHORT_SUM_LENGTH; /* initial value */
-
 /*
   a simple 32 bit checksum that can be upadted from either end
   (inspired by Mark Adler's Adler-32 checksum)
index 57b0e27..c215b05 100644 (file)
@@ -49,7 +49,6 @@ extern int logfile_format_has_i;
 extern int logfile_format_has_o_or_i;
 extern mode_t orig_umask;
 extern char *bind_address;
-extern char *sockopts;
 extern char *config_file;
 extern char *logfile_format;
 extern char *files_from;
diff --git a/io.c b/io.c
index 6e5c232..7cf272e 100644 (file)
--- a/io.c
+++ b/io.c
@@ -36,7 +36,6 @@
 extern int bwlimit;
 extern size_t bwlimit_writemax;
 extern int io_timeout;
-extern int allowed_lull;
 extern int am_server;
 extern int am_daemon;
 extern int am_sender;
@@ -47,7 +46,6 @@ extern int eol_nulls;
 extern int flist_eof;
 extern int list_only;
 extern int read_batch;
-extern int csum_length;
 extern int protect_args;
 extern int checksum_seed;
 extern int protocol_version;
@@ -60,7 +58,8 @@ extern int filesfrom_convert;
 extern iconv_t ic_send, ic_recv;
 #endif
 
-const char phase_unknown[] = "unknown";
+int csum_length = SHORT_SUM_LENGTH; /* initial value */
+int allowed_lull = 0;
 int ignore_timeout = 0;
 int batch_fd = -1;
 int msgdone_cnt = 0;
diff --git a/log.c b/log.c
index 6f9a47e..d50523b 100644 (file)
--- a/log.c
+++ b/log.c
@@ -53,7 +53,7 @@ extern char *logfile_name;
 extern iconv_t ic_chck;
 #endif
 #ifdef ICONV_OPTION
-extern iconv_t ic_send, ic_recv;
+extern iconv_t ic_recv;
 #endif
 extern char curr_dir[MAXPATHLEN];
 extern char *module_dir;
diff --git a/main.c b/main.c
index af14f36..c32457d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -32,7 +32,6 @@ extern int list_only;
 extern int am_root;
 extern int am_server;
 extern int am_sender;
-extern int am_generator;
 extern int am_daemon;
 extern int inc_recurse;
 extern int blocking_io;
@@ -85,6 +84,7 @@ extern struct file_list *first_flist;
 extern struct filter_list_struct daemon_filter_list;
 
 uid_t our_uid;
+int am_generator = 0;
 int local_server = 0;
 int daemon_over_rsh = 0;
 mode_t orig_umask = 0;
index 4a7516d..dce215e 100644 (file)
--- a/options.c
+++ b/options.c
@@ -78,7 +78,6 @@ int def_compress_level = Z_DEFAULT_COMPRESSION;
 int am_root = 0; /* 0 = normal, 1 = root, 2 = --super, -1 = --fake-super */
 int am_server = 0;
 int am_sender = 0;
-int am_generator = 0;
 int am_starting_up = 1;
 int relative_paths = -1;
 int implied_dirs = 1;
@@ -87,7 +86,6 @@ int msgs2stderr = 0;
 int allow_8bit_chars = 0;
 int force_delete = 0;
 int io_timeout = 0;
-int allowed_lull = 0;
 int prune_empty_dirs = 0;
 int use_qsort = 0;
 char *files_from = NULL;
index eb8b32e..b63428b 100755 (executable)
@@ -1,18 +1,75 @@
-#!/usr/bin/perl
-# This script finds extraneous "extern" variables in the *.c files.
-# Run it from inside the main rsync directory.
+#!/usr/bin/perl -w
+# This script checks the *.c files for extraneous "extern" variables,
+# for vars that are defined but not used, and for inconsistent array
+# sizes.  Run it from inside the main rsync directory.
 
 use strict;
 
+my %add_syscall_c = map { $_ => 1 } qw( t_stub.c t_unsafe.c tls.c trimslash.c );
+my %add_util_c = map { $_ => 1 } qw( t_stub.c t_unsafe.c );
+my %sizes;
+
+open(IN, '<', 'syscall.c') or die $!;
+undef $/; my $syscall_c = <IN>; $/ = "\n";
+close IN;
+$syscall_c =~ s/^extern\s.*//mg;
+
+open(IN, '<', 'util.c') or die $!;
+undef $/; my $util_c = <IN>; $/ = "\n";
+close IN;
+$util_c =~ s/^extern\s.*//mg;
+
 my @files = glob('*.c');
 
 foreach my $fn (@files) {
-    open(IN, '<', $fn) or die;
+    open(IN, '<', $fn) or die $!;
     undef $/; $_ = <IN>; $/ = "\n";
     close IN;
-    my @externs = /^extern .*?([^[\s(*;&.]+)(?:\[.*?\])?;/mg;
-    foreach my $find (@externs) {
-       my @matches = /(?<!\sstruct )\b(\Q$find\E)\b/g;
-       print $fn, ': ', $find, "\n" if @matches == 1;
+
+    my @vars = /^(?!(?:extern|enum)\s)([a-zA-Z]\S*\s+.*);/mg;
+    my @externs = /^extern\s+(.*);/mg;
+
+    $_ .= $syscall_c if $add_syscall_c{$fn};
+    $_ .= $util_c if $add_util_c{$fn};
+    s/INFO_GTE/info_levels/g;
+    s/DEBUG_GTE/debug_levels/g;
+
+    check_vars($fn, 'var', @vars);
+    check_vars($fn, 'extern', @externs);
+}
+
+exit;
+
+# The file's contents are in $_.
+sub check_vars
+{
+    my $fn = shift;
+    my $type = shift;
+
+    foreach my $line (@_) {
+       $line =~ s/\s*\{.*\}//;
+       $line =~ s/\s*\(.*\)//;
+       foreach my $item (split(/\s*,\s*/, $line)) {
+           $item =~ s/\s*=.*//;
+           my $sz = $item =~ s/(\[.*?\])// ? $1 : '';
+           my($var) = $item =~ /([^*\s]+)$/;
+           if (!defined $var) {
+               print "Bogus match? ($item)\n";
+               next;
+           }
+           if ($sz) {
+               if (defined $sizes{$var}) {
+                   if ($sizes{$var} ne $sz) {
+                       print $fn, ' has inconsistent size for "', $var,
+                           "\": $sizes{$var} vs $sz\n";
+                   }
+               } else {
+                   $sizes{$var} = $sz;
+               }
+           }
+           my @matches = /(?<!\sstruct )\b(\Q$var\E)(?!\w)/g;
+           push(@matches, /(\QSIGACTION(\E)/g) if $var eq 'sigact';
+           print $fn, " has extraneous $type: \"", $var, "\"\n" if @matches == 1;
+       }
     }
 }
index 943185a..7574653 100644 (file)
@@ -29,7 +29,7 @@ int read_only = 0;
 int list_only = 0;
 int preserve_perms = 0;
 int preserve_executability = 0;
-short info_levels[10], debug_levels[10];
+short info_levels[COUNT_INFO], debug_levels[COUNT_DEBUG];
 
 int
 main(int argc, char **argv)