From 93465f51bcc2484a1bdf0f94ed3b812fa5c39576 Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Mon, 21 Jul 2008 00:10:22 -0700 Subject: [PATCH] Improved var-checker and tweaked all the issues it found. --- checksum.c | 2 -- clientserver.c | 1 - io.c | 5 ++- log.c | 2 +- main.c | 2 +- options.c | 2 -- packaging/var-checker | 73 ++++++++++++++++++++++++++++++++++++++----- t_unsafe.c | 2 +- 8 files changed, 70 insertions(+), 19 deletions(-) diff --git a/checksum.c b/checksum.c index a5c0a432..9b6ec857 100644 --- a/checksum.c +++ b/checksum.c @@ -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) diff --git a/clientserver.c b/clientserver.c index 57b0e272..c215b053 100644 --- a/clientserver.c +++ b/clientserver.c @@ -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 6e5c2329..7cf272e8 100644 --- 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 6f9a47ed..d50523b8 100644 --- 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 af14f36c..c32457d4 100644 --- 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; diff --git a/options.c b/options.c index 4a7516d9..dce215e8 100644 --- 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; diff --git a/packaging/var-checker b/packaging/var-checker index eb8b32e1..b63428b7 100755 --- a/packaging/var-checker +++ b/packaging/var-checker @@ -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 = ; $/ = "\n"; +close IN; +$syscall_c =~ s/^extern\s.*//mg; + +open(IN, '<', 'util.c') or die $!; +undef $/; my $util_c = ; $/ = "\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 $/; $_ = ; $/ = "\n"; close IN; - my @externs = /^extern .*?([^[\s(*;&.]+)(?:\[.*?\])?;/mg; - foreach my $find (@externs) { - my @matches = /(?