From 6051eb29ab523abb4e0a8192ab253afe8737a9e4 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sat, 15 Jan 2011 11:59:44 +0100 Subject: [PATCH] Added another bunch of compiler warnings and fix code. --- bin/xbps-bin/main.c | 4 ++-- bin/xbps-dgraph/main.c | 4 ++-- bin/xbps-repo/main.c | 2 +- bin/xbps-repo/util.c | 5 +++-- bin/xbps-uhelper/main.c | 2 +- configure | 7 +++++-- lib/Makefile | 2 +- lib/download.c | 20 ++++++++++++++++++-- 8 files changed, 33 insertions(+), 13 deletions(-) diff --git a/bin/xbps-bin/main.c b/bin/xbps-bin/main.c index f25ac3ee..c8c06d94 100644 --- a/bin/xbps-bin/main.c +++ b/bin/xbps-bin/main.c @@ -42,7 +42,7 @@ struct list_pkgver_cb { size_t pkgver_len; }; -static void +static void __attribute__((noreturn)) usage(void) { fprintf(stderr, @@ -137,7 +137,7 @@ show_orphans(void) return 0; } -static void +static void __attribute__((noreturn)) cleanup(int signum) { xbps_end(); diff --git a/bin/xbps-dgraph/main.c b/bin/xbps-dgraph/main.c index 0dd1ccd6..5ec9e0eb 100644 --- a/bin/xbps-dgraph/main.c +++ b/bin/xbps-dgraph/main.c @@ -83,7 +83,7 @@ struct defprops { { .sect = "node-sub", .prop = "opt-fillcolor", .val = "grey" } }; -static void +static void __attribute__((noreturn)) die(const char *fmt, ...) { va_list ap; @@ -97,7 +97,7 @@ die(const char *fmt, ...) exit(EXIT_FAILURE); } -static void +static void __attribute__((noreturn)) usage(void) { fprintf(stderr, diff --git a/bin/xbps-repo/main.c b/bin/xbps-repo/main.c index 5d590a61..6c8633b1 100644 --- a/bin/xbps-repo/main.c +++ b/bin/xbps-repo/main.c @@ -35,7 +35,7 @@ #include #include "defs.h" -static void +static void __attribute__((noreturn)) usage(void) { fprintf(stderr, diff --git a/bin/xbps-repo/util.c b/bin/xbps-repo/util.c index 25966bbc..68c10f72 100644 --- a/bin/xbps-repo/util.c +++ b/bin/xbps-repo/util.c @@ -68,7 +68,8 @@ void show_pkg_info(prop_dictionary_t dict) { prop_object_t obj; - char size[64], *sep; + const char *sep; + char size[64]; int rv = 0; assert(dict != NULL); @@ -132,7 +133,7 @@ show_pkg_info(prop_dictionary_t dict) printf("Configuration files:\n"); sep = " "; (void)xbps_callback_array_iter_in_dict(dict, "conf_files", - list_strings_sep_in_array, sep); + list_strings_sep_in_array, __UNCONST(sep)); printf("\n"); } diff --git a/bin/xbps-uhelper/main.c b/bin/xbps-uhelper/main.c index d4fdf6b4..771040e0 100644 --- a/bin/xbps-uhelper/main.c +++ b/bin/xbps-uhelper/main.c @@ -55,7 +55,7 @@ write_plist_file(prop_dictionary_t dict, const char *file) } } -static void +static void __attribute__((noreturn)) usage(void) { fprintf(stderr, diff --git a/configure b/configure index 11f69832..45509f16 100755 --- a/configure +++ b/configure @@ -235,9 +235,12 @@ EOF # Check for some compiler warning flags. # for f in all extra error shadow "format=2" missing-prototypes \ - missing-declarations nested-externs \ + missing-declarations nested-externs vla no-overlength-strings \ + unsafe-loop-optimizations undef sign-compare format-security \ + missing-include-dirs format-nonliteral old-style-definition \ + init-self redundant-decls float-equal missing-noreturn \ cast-align cast-qual pointer-arith comment unused-macros \ - declaration-after-statement stack-protector; do + declaration-after-statement write-strings stack-protector; do check_compiler_flag ${f} W done diff --git a/lib/Makefile b/lib/Makefile index 17a90baf..4cd429f3 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -14,7 +14,7 @@ LIBPROP_OBJS += portableproplib/prop_stack.o portableproplib/prop_string.o LIBPROP_OBJS += portableproplib/prop_array_util.o portableproplib/prop_number.o LIBPROP_OBJS += portableproplib/prop_dictionary_util.o LIBPROP_OBJS += portableproplib/prop_data.o -LIBPROP_CFLAGS = -Wno-cast-qual -Wno-unused-parameter +LIBPROP_CFLAGS = -Wno-old-style-definition -Wno-cast-qual -Wno-unused-parameter ifdef USE_EXTERNAL_PROPLIB LIBPROP_OBJS = diff --git a/lib/download.c b/lib/download.c index 83371430..a805959a 100644 --- a/lib/download.c +++ b/lib/download.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2010 Juan Romero Pardines + * Copyright (c) 2009-2011 Juan Romero Pardines * Copyright (c) 2000-2004 Dag-Erling Coïdan Smørgrav * All rights reserved. * @@ -83,6 +83,22 @@ stat_eta(struct xferstat *xsp) return str; } +/** High precision double comparison + * \param[in] a The first double to compare + * \param[in] b The second double to compare + * \return true on equal within precison, false if not equal within defined precision. + */ +static inline bool +compare_double(const double a, const double b) +{ + const double precision = 0.00001; + + if ((a - precision) < b && (a + precision) > b) + return true; + else + return false; +} + /* * Compute and display transfer rate */ @@ -95,7 +111,7 @@ stat_bps(struct xferstat *xsp) delta = (xsp->last.tv_sec + (xsp->last.tv_usec / 1.e6)) - (xsp->start.tv_sec + (xsp->start.tv_usec / 1.e6)); - if (delta == 0.0) { + if (compare_double(delta, 0.0001)) { snprintf(str, sizeof str, "-- stalled --"); } else { bps = ((double)(xsp->rcvd - xsp->offset) / delta);