summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am29
-rw-r--r--client/internal.h3
-rw-r--r--configure.ac2
-rw-r--r--m4/cc-flags.m492
-rw-r--r--portable/snprintf.c9
-rw-r--r--ruby/remctl.c2
-rw-r--r--server/process.c6
-rw-r--r--tests/server/ssh-parse-t.c2
-rw-r--r--tests/util/network/server-t.c2
9 files changed, 113 insertions, 34 deletions
diff --git a/Makefile.am b/Makefile.am
index b172b89..19f830a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -322,23 +322,6 @@ distclean-local: clean-local
cd ruby && $(MAKE) distclean ; \
fi
-# A set of flags for warnings. Add -O because gcc won't find some warnings
-# without optimization turned on. Desirable warnings that can't be turned
-# on due to other problems:
-#
-# -Wconversion http://bugs.debian.org/488884 (htons warnings)
-#
-# Last checked against gcc 4.8.2 (2014-04-12). -D_FORTIFY_SOURCE=2 enables
-# warn_unused_result attribute markings on glibc functions on Linux, which
-# catches a few more issues.
-WARNINGS = -g -O -fstrict-overflow -fstrict-aliasing -D_FORTIFY_SOURCE=2 \
- -Wall -Wextra -Wendif-labels -Wformat=2 -Winit-self -Wswitch-enum \
- -Wstrict-overflow=5 -Wfloat-equal -Wdeclaration-after-statement \
- -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align \
- -Wwrite-strings -Wjump-misses-init -Wlogical-op -Wstrict-prototypes \
- -Wold-style-definition -Wmissing-prototypes -Wnormalized=nfc \
- -Wpacked -Wredundant-decls -Wnested-externs -Winline -Wvla -Werror
-
# Suppress some warnings for Perl, PHP, Python, and Ruby code because the
# auto-generated code otherwise generates them.
PERL_WARNINGS = -Wno-write-strings -Wno-nested-externs \
@@ -352,13 +335,13 @@ PYTHON_WARNINGS = -Wno-unused-parameter -Wno-strict-aliasing
RUBY_WARNINGS = -Wno-strict-prototypes -Wno-redundant-decls
warnings:
- $(MAKE) V=0 CFLAGS='$(WARNINGS)' \
- KRB5_CPPFLAGS='$(KRB5_CPPFLAGS_GCC)' \
- PERL_CFLAGS_EXTRA='$(PERL_WARNINGS)' \
- PHP_CFLAGS_EXTRA='$(PHP_WARNINGS)' \
- PYTHON_CFLAGS_EXTRA='$(PYTHON_WARNINGS)' \
+ $(MAKE) V=0 CFLAGS='$(WARNINGS_CFLAGS) $(AM_CFLAGS)' \
+ KRB5_CPPFLAGS='$(KRB5_CPPFLAGS_GCC)' \
+ PERL_CFLAGS_EXTRA='$(PERL_WARNINGS)' \
+ PHP_CFLAGS_EXTRA='$(PHP_WARNINGS)' \
+ PYTHON_CFLAGS_EXTRA='$(PYTHON_WARNINGS)' \
RUBY_CFLAGS_EXTRA='$(RUBY_WARNINGS)'
- $(MAKE) V=0 CFLAGS='$(WARNINGS)' \
+ $(MAKE) V=0 CFLAGS='$(WARNINGS_CFLAGS) $(AM_CFLAGS)' \
KRB5_CPPFLAGS='$(KRB5_CPPFLAGS_GCC)' $(check_PROGRAMS)
# The bits below are for the test suite, not for the main package.
diff --git a/client/internal.h b/client/internal.h
index 0d72731..c580bc8 100644
--- a/client/internal.h
+++ b/client/internal.h
@@ -54,7 +54,8 @@ BEGIN_DECLS
#pragma GCC visibility push(hidden)
/* Helper functions to set errors. */
-void internal_set_error(struct remctl *, const char *, ...);
+void internal_set_error(struct remctl *, const char *, ...)
+ __attribute__((__format__(printf, 2, 3), __nonnull__));
void internal_gssapi_error(struct remctl *, const char *error,
OM_uint32 major, OM_uint32 minor);
#ifdef HAVE_KRB5
diff --git a/configure.ac b/configure.ac
index 049370c..f0cdf27 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,7 +26,7 @@ dnl AM_PROG_AR is required for Automake 1.12 by Libtool but not defined at all
dnl (or needed) in Automake 1.11. Work around this bug.
AC_PROG_CC
AC_USE_SYSTEM_EXTENSIONS
-RRA_PROG_CC_CLANG
+RRA_PROG_CC_WARNINGS_FLAGS
AC_SYS_LARGEFILE
AM_PROG_CC_C_O
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
diff --git a/m4/cc-flags.m4 b/m4/cc-flags.m4
new file mode 100644
index 0000000..c45f92f
--- /dev/null
+++ b/m4/cc-flags.m4
@@ -0,0 +1,92 @@
+dnl Check whether the compiler supports particular flags.
+dnl
+dnl Provides RRA_PROG_CC_FLAG, which checks whether a compiler supports a
+dnl given flag. If it does, the commands in the second argument are run. If
+dnl not, the commands in the third argument are run.
+dnl
+dnl Provides RRA_PROG_CC_WARNINGS_FLAGS, which checks whether a compiler
+dnl supports a large set of warning flags and sets the WARNINGS_CFLAGS
+dnl substitution variable to all of the supported warning flags. (Note that
+dnl this may be too aggressive for some people.)
+dnl
+dnl Depends on RRA_PROG_CC_CLANG.
+dnl
+dnl The canonical version of this file is maintained in the rra-c-util
+dnl package, available at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+dnl
+dnl Copyright 2016 Russ Allbery <eagle@eyrie.org>
+dnl Copyright 2006, 2009, 2016
+dnl by Internet Systems Consortium, Inc. ("ISC")
+dnl
+dnl Permission to use, copy, modify, and distribute this software for any
+dnl purpose with or without fee is hereby granted, provided that the above
+dnl copyright notice and this permission notice appear in all copies.
+dnl
+dnl THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+dnl REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+dnl MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY
+dnl SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+dnl WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+dnl ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+dnl IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+dnl Used to build the result cache name.
+AC_DEFUN([_RRA_PROG_CC_FLAG_CACHE],
+[translit([rra_cv_compiler_c_$1], [-=], [__])])
+
+dnl Check whether a given flag is supported by the complier.
+AC_DEFUN([RRA_PROG_CC_FLAG],
+[AC_REQUIRE([AC_PROG_CC])
+ AC_MSG_CHECKING([if $CC supports $1])
+ AC_CACHE_VAL([_RRA_PROG_CC_FLAG_CACHE([$1])],
+ [save_CFLAGS=$CFLAGS
+ CFLAGS="$CFLAGS $1"
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [int foo = 0;])],
+ [_RRA_PROG_CC_FLAG_CACHE([$1])=yes],
+ [_RRA_PROG_CC_FLAG_CACHE([$1])=no])
+ CFLAGS=$save_CFLAGS])
+ AC_MSG_RESULT([$_RRA_PROG_CC_FLAG_CACHE([$1])])
+ AS_IF([test x"$_RRA_PROG_CC_FLAG_CACHE([$1])" = xyes], [$2], [$3])])
+
+dnl Determine the full set of viable warning flags for the current compiler.
+dnl
+dnl This is based partly on personal preference and is a fairly aggressive set
+dnl of warnings. Desirable warnings that can't be turned on due to other
+dnl problems:
+dnl
+dnl -Wconversion http://bugs.debian.org/488884 (htons warnings)
+dnl -Wsign-conversion Too much noise from ssize_t and flag variables
+dnl -Wstack-protector Too many false positives from small buffers
+dnl
+dnl Last checked against gcc 6.1.0 (2016-09-25). -D_FORTIFY_SOURCE=2 enables
+dnl warn_unused_result attribute markings on glibc functions on Linux, which
+dnl catches a few more issues. Add -O because gcc won't find some warnings
+dnl without optimization turned on.
+dnl
+dnl The warnings here are listed in the same order they're listed in the
+dnl "Preprocessor Options" and "Warning Options" chapters of the GCC manual.
+dnl
+dnl Sets WARNINGS_CFLAGS as a substitution variable.
+AC_DEFUN([RRA_PROG_CC_WARNINGS_FLAGS],
+[AC_REQUIRE([RRA_PROG_CC_CLANG])
+ AS_IF([test x"$CLANG" = xyes],
+ [WARNINGS_CFLAGS=""
+ m4_foreach_w([flag],
+ [-Weverything -Wno-padded],
+ [RRA_PROG_CC_FLAG(flag,
+ [WARNINGS_CFLAGS="${WARNINGS_CFLAGS} flag"])])],
+ [WARNINGS_CFLAGS="-g -O -D_FORTIFY_SOURCE=2"
+ m4_foreach_w([flag],
+ [-fstrict-overflow -fstrict-aliasing -Wcomments -Wendif-labels -Wall
+ -Wextra -Wformat=2 -Wformat-signedness -Wnull-dereference -Winit-self
+ -Wswitch-enum -Wuninitialized -Wstrict-overflow=5
+ -Wmissing-format-attribute -Wduplicated-cond -Wtrampolines
+ -Wfloat-equal -Wdeclaration-after-statement -Wshadow -Wpointer-arith
+ -Wbad-function-cast -Wcast-align -Wwrite-strings -Wdate-time
+ -Wjump-misses-init -Wfloat-conversion -Wlogical-op
+ -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes
+ -Wnormalized=nfc -Wpacked -Wredundant-decls -Wnested-externs -Winline
+ -Wvla -Werror],
+ [RRA_PROG_CC_FLAG(flag,
+ [WARNINGS_CFLAGS="${WARNINGS_CFLAGS} flag"])])])
+ AC_SUBST([WARNINGS_CFLAGS])])
diff --git a/portable/snprintf.c b/portable/snprintf.c
index 9818acd..9436311 100644
--- a/portable/snprintf.c
+++ b/portable/snprintf.c
@@ -79,6 +79,7 @@
* Russ Allbery <eagle@eyrie.org> 2000-08-26
* fixed return value to comply with C99
* fixed handling of snprintf(NULL, ...)
+ * added explicit casts for double to long long int conversion
*
* Hrvoje Niksic <hniksic@arsdigita.com> 2000-11-04
* include <stdio.h> for NULL.
@@ -612,7 +613,7 @@ static LDOUBLE abs_val (LDOUBLE value)
return result;
}
-static LDOUBLE pow10_int (int exp)
+static LLONG pow10_int (int exp)
{
LDOUBLE result = 1;
@@ -622,14 +623,14 @@ static LDOUBLE pow10_int (int exp)
exp--;
}
- return result;
+ return (LLONG) result;
}
static LLONG round_int (LDOUBLE value)
{
LLONG intpart;
- intpart = value;
+ intpart = (LLONG) value;
value = value - intpart;
if (value >= 0.5)
intpart++;
@@ -678,7 +679,7 @@ static int fmtfp (char *buffer, size_t *currlen, size_t maxlen,
if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */
#endif
- intpart = ufvalue;
+ intpart = (LLONG) ufvalue;
/* With %g precision is the number of significant digits, which
includes the digits in intpart. */
diff --git a/ruby/remctl.c b/ruby/remctl.c
index 5587b46..d691e69 100644
--- a/ruby/remctl.c
+++ b/ruby/remctl.c
@@ -486,7 +486,7 @@ rb_remctl_type_intern(enum remctl_output_type type)
for (i = 0; OUTPUT_TYPE[i].name != NULL; i++)
if (OUTPUT_TYPE[i].type == type)
return ID2SYM(rb_intern(OUTPUT_TYPE[i].name));
- rb_bug("Fell off the end while looking up remctl output type %d!\n", type);
+ rb_bug("Fell off the end while looking up remctl output type %u!\n", type);
}
diff --git a/server/process.c b/server/process.c
index 295c223..7037bc1 100644
--- a/server/process.c
+++ b/server/process.c
@@ -274,9 +274,11 @@ start(evutil_socket_t junk UNUSED, short what UNUSED, void *data)
if (initgroups(process->rule->user, process->rule->gid) != 0)
sysdie("cannot initgroups for %s\n", process->rule->user);
if (setgid(process->rule->gid) != 0)
- sysdie("cannot setgid to %d\n", process->rule->gid);
+ sysdie("cannot setgid to %lu\n",
+ (unsigned long) process->rule->gid);
if (setuid(process->rule->uid) != 0)
- sysdie("cannot setuid to %d\n", process->rule->uid);
+ sysdie("cannot setuid to %lu\n",
+ (unsigned long) process->rule->uid);
}
/*
diff --git a/tests/server/ssh-parse-t.c b/tests/server/ssh-parse-t.c
index 1be56b9..28c7a23 100644
--- a/tests/server/ssh-parse-t.c
+++ b/tests/server/ssh-parse-t.c
@@ -19,7 +19,7 @@
/*
* Check a struct iovec against a string.
*/
-static bool
+static bool __attribute__((__format__(printf, 3, 4)))
is_iovec_string(const char *wanted, const struct iovec *seen,
const char *format, ...)
{
diff --git a/tests/util/network/server-t.c b/tests/util/network/server-t.c
index 9aaf208..c82d725 100644
--- a/tests/util/network/server-t.c
+++ b/tests/util/network/server-t.c
@@ -404,7 +404,7 @@ test_all(const char *source_ipv4, const char *source_ipv6 UNUSED)
fd = fds[i];
if (listen(fd, 1) < 0)
sysbail("cannot listen to socket %d", fd);
- ok(fd != INVALID_SOCKET, "all address server test (part %d)", i + 1);
+ ok(fd != INVALID_SOCKET, "all address server test (part %u)", i + 1);
/* Get the socket type to determine what type of client to run. */
saddr = get_sockaddr(fd);