mirror of
https://github.com/coreutils/coreutils.git
synced 2024-12-03 23:13:50 +08:00
maint: enable -Wsuggest-attribute=format
* configure.ac (WERROR_CFLAGS): Enable -Wsuggest-attribute=format for lib/ and src/. * src/copy.c (copy_attr_error, copy_attr_allerror): Add ATTRIBUTE_FORMAT. (copy_attr): Ignore -Wsuggest-attribute=format in the small section of code that needs it ignored. * src/test.c (test_syntax_error): Mark with ATTRIBUTE_FORMAT. (binary_operator): Omit unnecessary NULL args, pacifying -Wsuggest-attribute=format.
This commit is contained in:
parent
d16821975e
commit
25e68323b9
@ -150,7 +150,6 @@ if test $gl_gcc_warnings != no; then
|
||||
nw="$nw -Wmissing-format-attribute" # copy.c
|
||||
nw="$nw -Wunsafe-loop-optimizations" # a few src/*.c
|
||||
nw="$nw -Winline" # system.h's readdir_ignoring_dot_and_dotdot
|
||||
nw="$nw -Wsuggest-attribute=format" # warns about copy.c and factor.c
|
||||
nw="$nw -Wvector-operation-performance" # warns about randperm.c
|
||||
|
||||
|
||||
@ -224,6 +223,7 @@ if test $gl_gcc_warnings != no; then
|
||||
nw="$nw -Wstrict-prototypes"
|
||||
# It's not worth being this picky about test programs.
|
||||
nw="$nw -Wsuggest-attribute=const"
|
||||
nw="$nw -Wsuggest-attribute=format"
|
||||
nw="$nw -Wsuggest-attribute=pure"
|
||||
gl_MANYWARN_COMPLEMENT([GNULIB_TEST_WARN_CFLAGS],
|
||||
[$GNULIB_WARN_CFLAGS], [$nw])
|
||||
|
44
src/copy.c
44
src/copy.c
@ -668,6 +668,7 @@ errno_unsupported (int err)
|
||||
}
|
||||
|
||||
#if USE_XATTR
|
||||
ATTRIBUTE_FORMAT ((printf, 2, 3))
|
||||
static void
|
||||
copy_attr_error (struct error_context *ctx _GL_UNUSED,
|
||||
char const *fmt, ...)
|
||||
@ -684,9 +685,10 @@ copy_attr_error (struct error_context *ctx _GL_UNUSED,
|
||||
}
|
||||
}
|
||||
|
||||
ATTRIBUTE_FORMAT ((printf, 2, 3))
|
||||
static void
|
||||
copy_attr_allerror (struct error_context *ctx _GL_UNUSED,
|
||||
char const *fmt, ...)
|
||||
char const *fmt, ...)
|
||||
{
|
||||
int err = errno;
|
||||
va_list ap;
|
||||
@ -728,26 +730,32 @@ static bool
|
||||
copy_attr (char const *src_path, int src_fd,
|
||||
char const *dst_path, int dst_fd, struct cp_options const *x)
|
||||
{
|
||||
int ret;
|
||||
bool all_errors = (!x->data_copy_required || x->require_preserve_xattr);
|
||||
bool some_errors = (!all_errors && !x->reduce_diagnostics);
|
||||
bool selinux_done = (x->preserve_security_context || x->set_security_context);
|
||||
struct error_context ctx =
|
||||
{
|
||||
.error = all_errors ? copy_attr_allerror : copy_attr_error,
|
||||
.quote = copy_attr_quote,
|
||||
.quote_free = copy_attr_free
|
||||
};
|
||||
if (0 <= src_fd && 0 <= dst_fd)
|
||||
ret = attr_copy_fd (src_path, src_fd, dst_path, dst_fd,
|
||||
selinux_done ? check_selinux_attr : NULL,
|
||||
(all_errors || some_errors ? &ctx : NULL));
|
||||
else
|
||||
ret = attr_copy_file (src_path, dst_path,
|
||||
selinux_done ? check_selinux_attr : NULL,
|
||||
(all_errors || some_errors ? &ctx : NULL));
|
||||
int (*check) (char const *, struct error_context *)
|
||||
= (x->preserve_security_context || x->set_security_context
|
||||
? check_selinux_attr : NULL);
|
||||
|
||||
return ret == 0;
|
||||
# if 4 < __GNUC__ + (8 <= __GNUC_MINOR__)
|
||||
/* Pacify gcc -Wsuggest-attribute=format through at least GCC 11.2.1. */
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
|
||||
# endif
|
||||
struct error_context *ctx
|
||||
= (all_errors || some_errors
|
||||
? (&(struct error_context) {
|
||||
.error = all_errors ? copy_attr_allerror : copy_attr_error,
|
||||
.quote = copy_attr_quote,
|
||||
.quote_free = copy_attr_free
|
||||
})
|
||||
: NULL);
|
||||
# if 4 < __GNUC__ + (8 <= __GNUC_MINOR__)
|
||||
# pragma GCC diagnostic pop
|
||||
# endif
|
||||
|
||||
return ! (0 <= src_fd && 0 <= dst_fd
|
||||
? attr_copy_fd (src_path, src_fd, dst_path, dst_fd, check, ctx)
|
||||
: attr_copy_file (src_path, dst_path, check, ctx));
|
||||
}
|
||||
#else /* USE_XATTR */
|
||||
|
||||
|
@ -85,6 +85,7 @@ static bool or (void);
|
||||
|
||||
static void beyond (void);
|
||||
|
||||
ATTRIBUTE_FORMAT ((printf, 1, 2))
|
||||
static _Noreturn void
|
||||
test_syntax_error (char const *format, ...)
|
||||
{
|
||||
@ -323,7 +324,7 @@ binary_operator (bool l_is_l)
|
||||
bool le, re;
|
||||
pos += 3;
|
||||
if (l_is_l || r_is_l)
|
||||
test_syntax_error (_("-nt does not accept -l"), NULL);
|
||||
test_syntax_error (_("-nt does not accept -l"));
|
||||
le = get_mtime (argv[op - 1], <);
|
||||
re = get_mtime (argv[op + 1], &rt);
|
||||
return le && (!re || timespec_cmp (lt, rt) > 0);
|
||||
@ -336,7 +337,7 @@ binary_operator (bool l_is_l)
|
||||
/* ef - hard link? */
|
||||
pos += 3;
|
||||
if (l_is_l || r_is_l)
|
||||
test_syntax_error (_("-ef does not accept -l"), NULL);
|
||||
test_syntax_error (_("-ef does not accept -l"));
|
||||
return (stat (argv[op - 1], &stat_buf) == 0
|
||||
&& stat (argv[op + 1], &stat_spare) == 0
|
||||
&& stat_buf.st_dev == stat_spare.st_dev
|
||||
@ -352,7 +353,7 @@ binary_operator (bool l_is_l)
|
||||
bool le, re;
|
||||
pos += 3;
|
||||
if (l_is_l || r_is_l)
|
||||
test_syntax_error (_("-ot does not accept -l"), NULL);
|
||||
test_syntax_error (_("-ot does not accept -l"));
|
||||
le = get_mtime (argv[op - 1], <);
|
||||
re = get_mtime (argv[op + 1], &rt);
|
||||
return re && (!le || timespec_cmp (lt, rt) < 0);
|
||||
|
Loading…
Reference in New Issue
Block a user