Fix problems caught by static checking
Most of these can be caught by configuring with --enable-gcc-warnings. Problem reported by Pavel Raiskup in: http://lists.gnu.org/archive/html/bug-tar/2015-09/msg00001.html * src/buffer.c (format_total_stats): Prefer pointer to const when it’s OK to use const. (default_total_format): Now const. * src/buffer.c (default_total_format): * src/exclist.c (excfile_head, excfile_tail, vcs_ignore_files): * src/misc.c (namebuf_add_dir, namebuf_finish): * src/tar.c (verbatim_files_from_option, option_set_in_cl) (optloc_eq, set_old_files_option): Now static. * src/common.h: Adjust to match the other changes described here. * src/exclist.c (info_cleanup_exclist): * src/tar.c (argp_program_version, argp_program_bug_address): Remove; unused. (parse_default_options): Define via prototype instead of old style. (parse_default_options, decode_options): Fill out incomplete initializers.
This commit is contained in:
@@ -517,7 +517,7 @@ print_stats (FILE *fp, const char *text, tarlong numbytes)
|
||||
from the archive), EOL is a delimiter to add at the end of the output
|
||||
line. */
|
||||
int
|
||||
format_total_stats (FILE *fp, const char **formats, int eor, int eol)
|
||||
format_total_stats (FILE *fp, char const *const *formats, int eor, int eol)
|
||||
{
|
||||
int n;
|
||||
|
||||
@@ -573,7 +573,7 @@ format_total_stats (FILE *fp, const char **formats, int eor, int eol)
|
||||
return n;
|
||||
}
|
||||
|
||||
const char *default_total_format[] = {
|
||||
static char const *const default_total_format[] = {
|
||||
N_("Total bytes read"),
|
||||
/* Amanda 2.4.1p1 looks for "Total bytes written: [0-9][0-9]*". */
|
||||
N_("Total bytes written"),
|
||||
|
||||
@@ -386,9 +386,6 @@ GLOBAL dev_t root_device;
|
||||
/* Unquote filenames */
|
||||
GLOBAL bool unquote_option;
|
||||
|
||||
/* Treat file names read from -T input verbatim */
|
||||
GLOBAL bool verbatim_files_from_option;
|
||||
|
||||
GLOBAL int savedir_sort_order;
|
||||
|
||||
/* Show file or archive names after transformation.
|
||||
@@ -456,7 +453,7 @@ void set_start_time (void);
|
||||
#define TF_READ 0
|
||||
#define TF_WRITE 1
|
||||
#define TF_DELETED 2
|
||||
int format_total_stats (FILE *fp, const char **formats, int eor, int eol);
|
||||
int format_total_stats (FILE *fp, char const *const *formats, int eor, int eol);
|
||||
void print_total_stats (void);
|
||||
|
||||
void mv_begin_write (const char *file_name, off_t totsize, off_t sizeleft);
|
||||
@@ -623,8 +620,6 @@ typedef struct namebuf *namebuf_t;
|
||||
namebuf_t namebuf_create (const char *dir);
|
||||
void namebuf_free (namebuf_t buf);
|
||||
char *namebuf_name (namebuf_t buf, const char *name);
|
||||
void namebuf_add_dir (namebuf_t buf, const char *name);
|
||||
char *namebuf_finish (namebuf_t buf);
|
||||
|
||||
const char *tar_dirname (void);
|
||||
|
||||
@@ -953,7 +948,6 @@ extern void (*fatal_exit_hook) (void);
|
||||
|
||||
void excfile_add (const char *name, int flags);
|
||||
void info_attach_exclist (struct tar_stat_info *dir);
|
||||
void info_cleanup_exclist (struct tar_stat_info *dir);
|
||||
void info_free_exclist (struct tar_stat_info *dir);
|
||||
bool excluded_name (char const *name, struct tar_stat_info *st);
|
||||
void exclude_vcs_ignores (void);
|
||||
|
||||
@@ -43,7 +43,7 @@ struct excfile
|
||||
char name[1];
|
||||
};
|
||||
|
||||
struct excfile *excfile_head, *excfile_tail;
|
||||
static struct excfile *excfile_head, *excfile_tail;
|
||||
|
||||
void
|
||||
excfile_add (const char *name, int flags)
|
||||
@@ -129,34 +129,6 @@ info_attach_exclist (struct tar_stat_info *dir)
|
||||
dir->exclude_list = head;
|
||||
}
|
||||
|
||||
void
|
||||
info_cleanup_exclist (struct tar_stat_info *dir)
|
||||
{
|
||||
struct exclist *ep = dir->exclude_list;
|
||||
|
||||
while (ep)
|
||||
{
|
||||
struct exclist *next = ep->next;
|
||||
|
||||
if (ep->flags & EXCL_NON_RECURSIVE)
|
||||
{
|
||||
|
||||
/* Remove the entry */
|
||||
if (ep->prev)
|
||||
ep->prev->next = ep->next;
|
||||
else
|
||||
dir->exclude_list = ep->next;
|
||||
|
||||
if (ep->next)
|
||||
ep->next->prev = ep->prev;
|
||||
|
||||
free_exclude (ep->excluded);
|
||||
free (ep);
|
||||
}
|
||||
ep = next;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
info_free_exclist (struct tar_stat_info *dir)
|
||||
{
|
||||
@@ -331,7 +303,7 @@ hg_addfn (struct exclude *ex, char const *pattern, int options, void *data)
|
||||
: (options & ~EXCLUDE_REGEX)) | *hgopt);
|
||||
}
|
||||
|
||||
struct vcs_ignore_file vcs_ignore_files[] = {
|
||||
static struct vcs_ignore_file vcs_ignore_files[] = {
|
||||
{ ".cvsignore", EXCL_NON_RECURSIVE, cvs_addfn, NULL, NULL },
|
||||
{ ".gitignore", 0, git_addfn, NULL, NULL },
|
||||
{ ".bzrignore", 0, bzr_addfn, NULL, NULL },
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
|
||||
#endif
|
||||
|
||||
static void namebuf_add_dir (namebuf_t, char const *);
|
||||
static char *namebuf_finish (namebuf_t);
|
||||
static const char *tar_getcdpath (int);
|
||||
|
||||
|
||||
@@ -1202,7 +1204,7 @@ namebuf_name (namebuf_t buf, const char *name)
|
||||
return buf->buffer;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
namebuf_add_dir (namebuf_t buf, const char *name)
|
||||
{
|
||||
static char dirsep[] = { DIRECTORY_SEPARATOR, 0 };
|
||||
@@ -1215,7 +1217,7 @@ namebuf_add_dir (namebuf_t buf, const char *name)
|
||||
buf->dir_length += strlen (name);
|
||||
}
|
||||
|
||||
char *
|
||||
static char *
|
||||
namebuf_finish (namebuf_t buf)
|
||||
{
|
||||
char *res = buf->buffer;
|
||||
|
||||
21
src/tar.c
21
src/tar.c
@@ -74,6 +74,9 @@ static int check_links_option;
|
||||
/* Number of allocated tape drive names. */
|
||||
static size_t allocated_archive_names;
|
||||
|
||||
/* Treat file names read from -T input verbatim */
|
||||
static bool verbatim_files_from_option;
|
||||
|
||||
|
||||
/* Miscellaneous. */
|
||||
|
||||
@@ -376,8 +379,6 @@ enum
|
||||
XATTR_INCLUDE
|
||||
};
|
||||
|
||||
const char *argp_program_version = "tar (" PACKAGE_NAME ") " VERSION;
|
||||
const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">";
|
||||
static char const doc[] = N_("\
|
||||
GNU 'tar' saves many files together into a single tape or disk archive, \
|
||||
and can restore individual files from the archive.\n\
|
||||
@@ -1080,7 +1081,7 @@ optloc_lookup (int id)
|
||||
}
|
||||
|
||||
/* Return true if the latest occurrence of option ID was in the command line */
|
||||
int
|
||||
static int
|
||||
option_set_in_cl (int id)
|
||||
{
|
||||
struct option_locus *loc = optloc_lookup (id);
|
||||
@@ -1090,7 +1091,7 @@ option_set_in_cl (int id)
|
||||
}
|
||||
|
||||
/* Compare two option locations */
|
||||
int
|
||||
static int
|
||||
optloc_eq (struct option_locus *a, struct option_locus *b)
|
||||
{
|
||||
if (a->source != b->source)
|
||||
@@ -1458,11 +1459,11 @@ static int sort_mode_flag[] = {
|
||||
|
||||
ARGMATCH_VERIFY (sort_mode_arg, sort_mode_flag);
|
||||
|
||||
void
|
||||
static void
|
||||
set_old_files_option (int code, struct option_locus *loc)
|
||||
{
|
||||
struct option_locus *prev;
|
||||
static char *code_to_opt[] = {
|
||||
static char const *const code_to_opt[] = {
|
||||
"--overwrite-dir",
|
||||
"--no-overwrite-dir",
|
||||
"--overwrite",
|
||||
@@ -2460,12 +2461,12 @@ more_options (int argc, char **argv, struct option_locus *loc)
|
||||
USAGE_ERROR ((0, 0, _("non-option arguments in %s"), loc->name));
|
||||
}
|
||||
|
||||
void
|
||||
parse_default_options ()
|
||||
static void
|
||||
parse_default_options (void)
|
||||
{
|
||||
char *opts = getenv ("TAR_OPTIONS");
|
||||
struct wordsplit ws;
|
||||
struct option_locus loc = { OPTS_ENVIRON, "TAR_OPTIONS", 0 };
|
||||
struct option_locus loc = { OPTS_ENVIRON, "TAR_OPTIONS", 0, 0 };
|
||||
|
||||
if (!opts)
|
||||
return;
|
||||
@@ -2487,7 +2488,7 @@ static void
|
||||
decode_options (int argc, char **argv)
|
||||
{
|
||||
int idx;
|
||||
struct option_locus loc = { OPTS_COMMAND_LINE };
|
||||
struct option_locus loc = { OPTS_COMMAND_LINE, 0, 0, 0 };
|
||||
|
||||
argp_version_setup ("tar", tar_authors);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user