diff options
author | Wayne Davison <wayned@samba.org> | 2008-07-21 00:10:22 -0700 |
---|---|---|
committer | Wayne Davison <wayned@samba.org> | 2008-07-21 00:10:22 -0700 |
commit | 93465f51bcc2484a1bdf0f94ed3b812fa5c39576 (patch) | |
tree | 91193ab84f22ced214fd20496b1570b74ab93635 | |
parent | 26a7af26aa149017e2b16a0b96d74d3bacc7a7f1 (diff) | |
download | android_external_rsync-93465f51bcc2484a1bdf0f94ed3b812fa5c39576.tar.gz android_external_rsync-93465f51bcc2484a1bdf0f94ed3b812fa5c39576.tar.bz2 android_external_rsync-93465f51bcc2484a1bdf0f94ed3b812fa5c39576.zip |
Improved var-checker and tweaked all the issues it found.
-rw-r--r-- | checksum.c | 2 | ||||
-rw-r--r-- | clientserver.c | 1 | ||||
-rw-r--r-- | io.c | 5 | ||||
-rw-r--r-- | log.c | 2 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | options.c | 2 | ||||
-rwxr-xr-x | packaging/var-checker | 73 | ||||
-rw-r--r-- | t_unsafe.c | 2 |
8 files changed, 70 insertions, 19 deletions
@@ -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; @@ -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; @@ -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; @@ -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; @@ -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 = <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; + } } } @@ -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) |