bug-tar
[Top][All Lists]
Advanced

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

Re: [Bug-tar] two small patches


From: Paul Eggert
Subject: Re: [Bug-tar] two small patches
Date: Wed, 16 Jun 2010 13:09:55 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100423 Thunderbird/3.0.4

I used GCC's warning options to find all instances of the
missing-declaration problem you reported, along with some other
problems, and installed the following fix into GNU tar.  Thanks again
for reporting the problem.  This process did seem to catch one actual
bug, in extract_node.

The patch enclosed below omits trivial white space changes at end of
line.

Remove some lint, found by gcc -W etc.

* src/common.h (label_notfound): New decl.
* src/buffer.c (set_volume_start_time, compress_type):
(guess_seekable_archive, open_compressed_archive, init_buffer):
(_flush_write, archive_is-dev, increase_volume_number):
(change_tape_menu, try_new_volume, add_chunk_header):
(multi_volume_sync):
Declare as 'static' if it's not exported.
Use function prototype (void) rather than old-style ().
* src/checkpoint.c (expand_checkpoint_string): Likewise.
* src/incremen.c (dirlist_replace_prefix, makedumpdir, read_incr_db_2):
Likewise.
* src/list.c (print_volume_label): Likewise.
* src/misc.c (normalize_filename_x): Likewise.
* src/names.c (make_name, free_name, check_name_alloc, name_next_elt):
Likewise.
* src/tar.c (tar_list_quoting_style, add_exclude_array):
(set_stat_signal): Likewise.
* src/transform.c (new_transform, _single_transform_name_to_obstack):
(_transform_name_to_obstack): Likewise.
* src/unlink.c (dunlink_alloc): Likewise.

* src/buffer.c (struct zip_magic): Use const when appropriate.
* src/incremen.c (obstack_code_rename, write_directory_file_entry):
Likewise.
* src/sparse.c (COPY_STRING): Likewise.
* src/system.c (dec_to_env, time_to_env, oct_to_env, str_to_env):
(chr_to_env): Likewise.
* src/tar.c (tar_list_quoting_style, set_stat_signal): Likewise.

* src/extract.c (extract_node): Don't return garbage.

* src/names.c: Remove old-style declarations of getgrnam etc.
All modern systems declare these, and it's not worth the hassle
of ignoring the warnings on modern systems for old-style decls.
diff --git a/src/buffer.c b/src/buffer.c
index dfc8456..239d3f1 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -175,8 +175,8 @@ set_start_time ()
   last_stat_time = start_time;
 }
 
-void
-set_volume_start_time ()
+static void
+set_volume_start_time (void)
 {
   gettime (&volume_start_time);
   last_stat_time = volume_start_time;
@@ -211,9 +211,9 @@ struct zip_magic
 {
   enum compress_type type;
   size_t length;
-  char *magic;
-  char *program;
-  char *option;
+  char const *magic;
+  char const *program;
+  char const *option;
 };
 
 static struct zip_magic const magic[] = {
@@ -234,7 +234,7 @@ static struct zip_magic const magic[] = {
 #define compress_program(t) magic[t].program
 
 /* Check if the file ARCHIVE is a compressed archive. */
-enum compress_type
+static enum compress_type
 check_compressed_archive (bool *pshort)
 {
   struct zip_magic const *p;
@@ -267,7 +267,7 @@ check_compressed_archive (bool *pshort)
 
 /* Guess if the archive is seekable. */
 static void
-guess_seekable_archive ()
+guess_seekable_archive (void)
 {
   struct stat st;
 
@@ -299,8 +299,8 @@ guess_seekable_archive ()
 /* Open an archive named archive_name_array[0]. Detect if it is
    a compressed archive of known type and use corresponding decompression
    program if so */
-int
-open_compressed_archive ()
+static int
+open_compressed_archive (void)
 {
   archive = rmtopen (archive_name_array[0], O_RDONLY | O_BINARY,
                      MODE_RW, rsh_command_option);
@@ -486,7 +486,7 @@ xclose (int fd)
 }
 
 static void
-init_buffer ()
+init_buffer (void)
 {
   if (! record_buffer_aligned[record_index])
     record_buffer_aligned[record_index] =
@@ -657,7 +657,7 @@ _open_archive (enum access_mode wanted_access)
 }
 
 /* Perform a write to flush the buffer.  */
-ssize_t
+static ssize_t
 _flush_write (void)
 {
   ssize_t status;
@@ -713,7 +713,7 @@ archive_read_error (void)
 }
 
 static bool
-archive_is_dev ()
+archive_is_dev (void)
 {
   struct stat st;
 
@@ -956,7 +956,7 @@ closeout_volume_number (void)
 
 
 static void
-increase_volume_number ()
+increase_volume_number (void)
 {
   global_volno++;
   if (global_volno < 0)
@@ -964,7 +964,7 @@ increase_volume_number ()
   volno++;
 }
 
-void
+static void
 change_tape_menu (FILE *read_file)
 {
   char *input_buffer = NULL;
@@ -1177,8 +1177,8 @@ read_header0 (struct tar_stat_info *info)
   return false;
 }
 
-bool
-try_new_volume ()
+static bool
+try_new_volume (void)
 {
   size_t status;
   union block *header;
@@ -1477,7 +1477,7 @@ add_volume_label (void)
 }
 
 static void
-add_chunk_header ()
+add_chunk_header (void)
 {
   if (archive_format == POSIX_FORMAT)
     {
@@ -1568,7 +1568,7 @@ add_multi_volume_header (void)
 
 /* Synchronize multi-volume globals */
 static void
-multi_volume_sync ()
+multi_volume_sync (void)
 {
   if (multi_volume_option)
     {
diff --git a/src/checkpoint.c b/src/checkpoint.c
index 9f031f7..a2896ab 100644
--- a/src/checkpoint.c
+++ b/src/checkpoint.c
@@ -126,7 +126,7 @@ checkpoint_finish_compile ()
     checkpoint_option = DEFAULT_CHECKPOINT;
 }
 
-char *
+static char *
 expand_checkpoint_string (const char *input, bool do_write, unsigned cpn)
 {
   const char *opstr = do_write ? gettext ("write") : gettext ("read");
@@ -267,4 +267,3 @@ checkpoint_run (bool do_write)
   if (checkpoint_option && !(++checkpoint % checkpoint_option))
     run_checkpoint_actions (do_write);
 }  
-
diff --git a/src/common.h b/src/common.h
index 3b91f46..9e42eec 100644
--- a/src/common.h
+++ b/src/common.h
@@ -692,6 +692,7 @@ struct name *addname (char const *string, int change_dir,
 void remname (struct name *name);
 bool name_match (const char *name);
 void names_notfound (void);
+void label_notfound (void);
 void collect_and_sort_names (void);
 struct name *name_scan (const char *name);
 struct name const *name_from_list (void);
@@ -858,4 +859,3 @@ void finish_deferred_unlinks (void);
 
 /* Module exit.c */
 extern void (*fatal_exit_hook) (void);
-
diff --git a/src/extract.c b/src/extract.c
index 531654a..c3a99e0 100644
--- a/src/extract.c
+++ b/src/extract.c
@@ -1065,7 +1065,6 @@ extract_symlink (char *file_name, int typeflag)
 static int
 extract_node (char *file_name, int typeflag)
 {
-  int status;
   int interdir_made = 0;
   mode_t mode = current_stat_info.stat.st_mode & ~ current_umask;
   mode_t invert_permissions =
@@ -1088,7 +1087,7 @@ extract_node (char *file_name, int typeflag)
 
   set_stat (file_name, &current_stat_info, NULL, invert_permissions,
            ARCHIVED_PERMSTATUS, typeflag);
-  return status;
+  return 0;
 }
 #endif
 
diff --git a/src/incremen.c b/src/incremen.c
index 0d0b4ff..e61eb79 100644
--- a/src/incremen.c
+++ b/src/incremen.c
@@ -290,7 +290,7 @@ attach_directory (const char *name)
 }
                 
 
-void
+static void
 dirlist_replace_prefix (const char *pref, const char *repl)
 {
   struct directory *dp;
@@ -616,7 +616,7 @@ procdir (const char *name_buffer, struct stat *stat_data,
    DIRECTORY->dump is replaced with the created template. Each entry is
    prefixed with ' ' if it was present in DUMP and with 'Y' otherwise. */
 
-void
+static void
 makedumpdir (struct directory *directory, const char *dir)
 {
   size_t i,
@@ -809,9 +809,9 @@ name_fill_directory (struct name *name, dev_t device, bool 
cmdline)
 
 
 static void
-obstack_code_rename (struct obstack *stk, char *from, char *to)
+obstack_code_rename (struct obstack *stk, char const *from, char const *to)
 {
-  char *s;
+  char const *s;
 
   s = from[0] == 0 ? from :
                      safer_name_suffix (from, false, absolute_names_option);
@@ -1217,7 +1217,7 @@ read_timespec (FILE *fp, struct timespec *pval)
 
 /* Read incremental snapshot format 2 */
 static void
-read_incr_db_2 ()
+read_incr_db_2 (void)
 {
   uintmax_t u;
   struct obstack stk;
@@ -1367,7 +1367,7 @@ write_directory_file_entry (void *entry, void *data)
   if (DIR_IS_FOUND (directory))
     {
       char buf[UINTMAX_STRSIZE_BOUND];
-      char *s;
+      char const *s;
 
       s = DIR_IS_NFS (directory) ? "1" : "0";
       fwrite (s, 2, 1, fp);
diff --git a/src/list.c b/src/list.c
index ac7c8fb..dad725a 100644
--- a/src/list.c
+++ b/src/list.c
@@ -1292,8 +1292,8 @@ simple_print_header (struct tar_stat_info *st, union 
block *blk,
 }
 
 
-void
-print_volume_label ()
+static void
+print_volume_label (void)
 {
   struct tar_stat_info vstat;
   union block vblk;
diff --git a/src/misc.c b/src/misc.c
index ff7e4b2..3e7941d 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -235,7 +235,7 @@ zap_slashes (char *name)
 
 /* Normalize NAME by resolving any relative references and
    removing trailing slashes.  Destructive version: modifies its argument. */ 
-int
+static int
 normalize_filename_x (char *name)
 {
   char *p, *q;
@@ -961,4 +961,3 @@ namebuf_name (namebuf_t buf, const char *name)
   strcpy (buf->buffer + buf->dir_length, name);
   return buf->buffer;
 }
-
diff --git a/src/names.c b/src/names.c
index a3c6f58..f1e5ab1 100644
--- a/src/names.c
+++ b/src/names.c
@@ -27,15 +27,6 @@
 
 /* User and group names.  */
 
-struct group *getgrnam ();
-struct passwd *getpwnam ();
-#if ! HAVE_DECL_GETPWUID
-struct passwd *getpwuid ();
-#endif
-#if ! HAVE_DECL_GETGRGID
-struct group *getgrgid ();
-#endif
-
 /* Make sure you link with the proper libraries if you are running the
    Yellow Peril (thanks for the good laugh, Ian J.!), or, euh... NIS.
    This code should also be modified for non-UNIX systems to do something
@@ -179,7 +170,7 @@ gname_to_gid (char const *gname, gid_t *gidp)
 }
 
 
-struct name *
+static struct name *
 make_name (const char *file_name)
 {
   struct name *p = xzalloc (sizeof (*p));
@@ -190,7 +181,7 @@ make_name (const char *file_name)
   return p;
 }
 
-void
+static void
 free_name (struct name *p)
 {
   if (p)
@@ -241,7 +232,7 @@ static size_t name_index;    /* how many of the entries 
have we scanned? */
 
 /* Check the size of name_array, reallocating it as necessary.  */
 static void
-check_name_alloc ()
+check_name_alloc (void)
 {
   if (names == allocated_names)
     {
@@ -316,7 +307,7 @@ static int matching_flags; /* exclude_fnmatch options */
    
    Entries of type NELT_FMASK cause updates of the matching_flags
    value. */
-struct name_elt *
+static struct name_elt *
 name_next_elt (int change_dirs)
 {
   static struct name_elt entry;
diff --git a/src/sparse.c b/src/sparse.c
index 9fde508..4a391a9 100644
--- a/src/sparse.c
+++ b/src/sparse.c
@@ -991,7 +991,7 @@ pax_dump_header_1 (struct tar_sparse_file *file)
 #define COPY_STRING(b,dst,src) do                \
  {                                               \
    char *endp = b->buffer + BLOCKSIZE;           \
-   char *srcp = src;                             \
+   char const *srcp = src;                       \
    while (*srcp)                                 \
      {                                           \
        if (dst == endp)                          \
diff --git a/src/system.c b/src/system.c
index d646822..345cc07 100644
--- a/src/system.c
+++ b/src/system.c
@@ -575,7 +575,7 @@ sys_child_open_for_uncompress (void)
 
 
 static void
-dec_to_env (char *envar, uintmax_t num)
+dec_to_env (char const *envar, uintmax_t num)
 {
   char buf[UINTMAX_STRSIZE_BOUND];
   char *numstr;
@@ -586,7 +586,7 @@ dec_to_env (char *envar, uintmax_t num)
 }
 
 static void
-time_to_env (char *envar, struct timespec t)
+time_to_env (char const *envar, struct timespec t)
 {
   char buf[TIMESPEC_STRSIZE_BOUND];
   if (setenv (envar, code_timespec (t, buf), 1) != 0)
@@ -594,7 +594,7 @@ time_to_env (char *envar, struct timespec t)
 }
 
 static void
-oct_to_env (char *envar, unsigned long num)
+oct_to_env (char const *envar, unsigned long num)
 {
   char buf[1+1+(sizeof(unsigned long)*CHAR_BIT+2)/3];
 
@@ -604,7 +604,7 @@ oct_to_env (char *envar, unsigned long num)
 }
 
 static void
-str_to_env (char *envar, char const *str)
+str_to_env (char const *envar, char const *str)
 {
   if (str)
     {
@@ -616,7 +616,7 @@ str_to_env (char *envar, char const *str)
 }
 
 static void
-chr_to_env (char *envar, char c)
+chr_to_env (char const *envar, char c)
 {
   char buf[2];
   buf[0] = c;
@@ -813,7 +813,7 @@ sys_exec_info_script (const char **archive_name, int 
volume_number)
 
   argv[0] = "/bin/sh";
   argv[1] = "-c";
-  argv[2] = (char*) info_script_option;
+  argv[2] = (char *) info_script_option;
   argv[3] = NULL;
 
   execv (argv[0], argv);
@@ -860,7 +860,7 @@ sys_exec_checkpoint_script (const char *script_name,
                                 archive_format : current_format), 1);
   argv[0] = "/bin/sh";
   argv[1] = "-c";
-  argv[2] = (char*) script_name;
+  argv[2] = (char *) script_name;
   argv[3] = NULL;
 
   execv (argv[0], argv);
diff --git a/src/tar.c b/src/tar.c
index 21c396d..5b61144 100644
--- a/src/tar.c
+++ b/src/tar.c
@@ -220,8 +220,8 @@ subcommand_string (enum subcommand c)
   abort ();
 }
 
-void
-tar_list_quoting_styles (struct obstack *stk, char *prefix)
+static void
+tar_list_quoting_styles (struct obstack *stk, char const *prefix)
 {
   int i;
   size_t prefixlen = strlen (prefix);
@@ -235,7 +235,7 @@ tar_list_quoting_styles (struct obstack *stk, char *prefix)
     }
 }
 
-void
+static void
 tar_set_quoting_style (char *arg)
 {
   int i;
@@ -891,7 +891,7 @@ static char const * const backup_file_table[] = {
   NULL
 };
 
-void
+static void
 add_exclude_array (char const * const * fv)
 {
   int i;
@@ -966,14 +966,14 @@ stat_on_signal (int signo)
 #endif
 }
 
-void
+static void
 set_stat_signal (const char *name)
 {
   static struct sigtab
   {
-    char *name;
+    char const *name;
     int signo;
-  } sigtab[] = {
+  } const sigtab[] = {
     { "SIGUSR1", SIGUSR1 },
     { "USR1", SIGUSR1 },
     { "SIGUSR2", SIGUSR2 },
@@ -985,7 +985,7 @@ set_stat_signal (const char *name)
     { "SIGQUIT", SIGQUIT },
     { "QUIT", SIGQUIT }
   };
-  struct sigtab *p;
+  struct sigtab const *p;
 
   for (p = sigtab; p < sigtab + sizeof (sigtab) / sizeof (sigtab[0]); p++)
     if (strcmp (p->name, name) == 0)
diff --git a/src/transform.c b/src/transform.c
index 03c06f6..c35133f 100644
--- a/src/transform.c
+++ b/src/transform.c
@@ -75,7 +75,7 @@ int transform_flags = XFORM_ALL;
 static struct transform *transform_head, *transform_tail;
 
 static struct transform *
-new_transform ()
+new_transform (void)
 {
   struct transform *p = xzalloc (sizeof *p);
   if (transform_tail)
@@ -457,7 +457,7 @@ run_case_conv (enum case_ctl_type case_ctl, char *ptr, 
size_t size)
 static struct obstack stk;
 static bool stk_init;
 
-void
+static void
 _single_transform_name_to_obstack (struct transform *tf, char *input)
 {
   regmatch_t *rmp;
@@ -577,7 +577,7 @@ _single_transform_name_to_obstack (struct transform *tf, 
char *input)
   free (rmp);
 }
 
-bool
+static bool
 _transform_name_to_obstack (int flags, char *input, char **output)
 {
   struct transform *tf;
diff --git a/src/unlink.c b/src/unlink.c
index 2af6f99..817ab4a 100644
--- a/src/unlink.c
+++ b/src/unlink.c
@@ -42,7 +42,7 @@ static struct deferred_unlink *dunlink_avail;
 size_t deferred_unlink_delay = 0;
 
 static struct deferred_unlink *
-dunlink_alloc ()
+dunlink_alloc (void)
 {
   struct deferred_unlink *p;
   if (dunlink_avail)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]