From b3e02ce0baf9d00572cb50b2087c69c90ac89252 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Tue, 17 Jul 2012 17:50:35 +0200 Subject: [PATCH] all: fix compiler warninings Use compiler warnings from coreutils to check nothing complains, and fix everything that did. CFLAGS='-Wall -W -Wformat-y2k -Wformat-security -Winit-self -Wmissing-include-dirs -Wunused -Wunknown-pragmas -Wstrict-aliasing -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Wmissing-declarations -Wmissing-noreturn -Wpacked -Winvalid-pch -Wvolatile-register-var -Wdisabled-optimization -Woverlength-strings -Wbuiltin-macro-redefined -Wmudflap -Wpacked-bitfield-compat -Wsync-nand -Wattributes -Wcoverage-mismatch -Wabi -Wcpp -Wdeprecated -Wdeprecated-declarations -Wdiv-by-zero -Wendif-labels -Wextra -Wformat-contains-nul -Wformat-extra-args -Wformat-zero-length -Wformat=2 -Wmultichar -Wnormalized=nfc -Woverflow -Wpointer-to-int-cast -Wpragmas -Wsuggest-attribute=noreturn -Wtrampolines -Wno-sign-compare -Wno-unused-parameter -Wsuggest-attribute=noreturn -Wno-format-nonliteral -Wno-logical-op -fdiagnostics-show-option -funit-at-a-time' Signed-off-by: Sami Kerola --- src/analyze.c | 2 +- src/dhcpd-pools.c | 2 +- src/dhcpd-pools.h | 2 +- src/getdata.c | 2 +- src/other.c | 11 ++++++----- src/output.c | 22 ++++++++++++---------- 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/analyze.c b/src/analyze.c index ad5bab8..b1c1b0a 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -42,7 +42,7 @@ #include "dhcpd-pools.h" /* Clean up data */ -int ip_sort(struct leases_t *a, struct leases_t *b) +static int ip_sort(struct leases_t *a, struct leases_t *b) { if (a->ip < b->ip) return -1; diff --git a/src/dhcpd-pools.c b/src/dhcpd-pools.c index 7a2313a..a532425 100644 --- a/src/dhcpd-pools.c +++ b/src/dhcpd-pools.c @@ -61,7 +61,7 @@ int main(int argc, char **argv) { int i, c, sorts = 0; int option_index = 0; - char *tmp; + char const *tmp; struct range_t *tmp_ranges; enum { OPT_WARN = CHAR_MAX + 1, diff --git a/src/dhcpd-pools.h b/src/dhcpd-pools.h index c9559d1..ed4623e 100644 --- a/src/dhcpd-pools.h +++ b/src/dhcpd-pools.h @@ -178,7 +178,7 @@ void *safe_malloc(const size_t size) ; void *safe_realloc(void *__restrict ptr, const size_t size); char *safe_strdup(const char *__restrict str) __attribute__ ((nonnull(1))); -int xstrstr(char *__restrict a, char *__restrict b, int len); +int xstrstr(char *__restrict a, const char *__restrict b, int len); double strtod_or_err(const char *__restrict str, const char *__restrict errmesg); int close_stream(FILE * stream); void close_stdout(void); diff --git a/src/getdata.c b/src/getdata.c index 6e8657d..a5b7990 100644 --- a/src/getdata.c +++ b/src/getdata.c @@ -200,7 +200,7 @@ int nth_field(int n, char *restrict dest, const char *restrict src) } /* dhcpd.conf interesting words */ -int is_interesting_config_clause(char *restrict s) +static int is_interesting_config_clause(char const *restrict s) { if (strstr(s, "range")) { return 3; diff --git a/src/other.c b/src/other.c index 5551ce3..05e1cd7 100644 --- a/src/other.c +++ b/src/other.c @@ -104,7 +104,7 @@ int #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) __attribute__ ((hot)) #endif - xstrstr(char *restrict a, char *restrict b, int len) + xstrstr(char *restrict a, const char *restrict b, int len) { int i; /* two spaces are very common in lease file, after them @@ -137,7 +137,7 @@ char *safe_strdup(const char *restrict str) } /* Return percentage value */ -double strtod_or_err(const char *str, const char *errmesg) +double strtod_or_err(const char *restrict str, const char *restrict errmesg) { double num; char *end = NULL; @@ -158,16 +158,17 @@ double strtod_or_err(const char *str, const char *errmesg) errx(EXIT_FAILURE, "%s: '%s'", errmesg, str); } -void flip_ranges(struct range_t *restrict ranges, struct range_t *restrict tmp_ranges) +void flip_ranges(struct range_t *restrict flip_me, + struct range_t *restrict tmp_ranges) { unsigned int i = num_ranges - 1, j; for (j = 0; j < num_ranges; j++) { - *(tmp_ranges + j) = *(ranges + i); + *(tmp_ranges + j) = *(flip_me + i); i--; } - memcpy(ranges, tmp_ranges, num_ranges * sizeof(struct range_t)); + memcpy(flip_me, tmp_ranges, num_ranges * sizeof(struct range_t)); } /* Free memory, flush buffers etc */ diff --git a/src/output.c b/src/output.c index 9a4f312..c4c3db2 100644 --- a/src/output.c +++ b/src/output.c @@ -314,7 +314,7 @@ int output_xml(void) return 0; } -void html_header(FILE *restrict f) +static void html_header(FILE *restrict f) { char outstr[200]; struct tm *tmp; @@ -388,7 +388,7 @@ void html_header(FILE *restrict f) fprintf(f, "The lease file mtime: %s", outstr); } -void html_footer(FILE *restrict f) +static void html_footer(FILE *restrict f) { fprintf(f, "


\n"); fprintf(f, "
\n"); @@ -404,44 +404,46 @@ void html_footer(FILE *restrict f) fprintf(f, "\n"); } -void newrow(FILE *restrict f) +static void newrow(FILE *restrict f) { fprintf(f, "\n"); } -void endrow(FILE *restrict f) +static void endrow(FILE *restrict f) { fprintf(f, "\n\n"); } -void output_line(FILE *restrict f, char *restrict type, char *restrict class, char *restrict text) +static void output_line(FILE *restrict f, char const *restrict type, + char const *restrict class, char const *restrict text) { fprintf(f, " <%s class=%s>%s\n", type, class, text, type); } -void output_long(FILE *restrict f, char *restrict type, unsigned long unlong) +static void output_long(FILE *restrict f, char const *restrict type, + unsigned long unlong) { fprintf(f, " <%s class=ralign>%lu\n", type, unlong, type); } -void output_float(FILE * f, char *restrict type, float fl) +static void output_float(FILE * f, char const *restrict type, float fl) { fprintf(f, " <%s class=ralign>%.3f\n", type, fl, type); } -void table_start(FILE *restrict f) +static void table_start(FILE *restrict f) { fprintf(f, "\n"); } -void table_end(FILE *restrict f) +static void table_end(FILE *restrict f) { fprintf(f, "
\n"); } -void newsection(FILE *restrict f, char *restrict title) +static void newsection(FILE *restrict f, char const *restrict title) { newrow(f); output_line(f, "td", "calign", " ");