From 24a1cb649dd3b5c5d93fa470ebfe4d88abb2af00 Mon Sep 17 00:00:00 2001 From: oetiker Date: Wed, 1 Oct 2008 20:01:43 +0000 Subject: [PATCH] Fixes for the following compiler warnings: - unused variable - unused parameter - assignment / argument discards qualifiers from pointer target type - comparison between signed and unsigned - too many arguments to function - assignment makes pointer from integer without a cast - incompatible pointer type - differ in signedness - implicit declaration of function - enumeration value not handled in switch - value computed is not used Most notably, a possible segfault in the Rrd_Lastupdate() code of the TCL bindings has been fixed. Also, -Wundef (warn if an undefined identifier is evaluated in an #if directive) has been removed from CFLAGS. I don't see any problem with letting undefined identifiers evaluate to "false" in rrdtool. Keeping that option would produce a lot of (imho unnecessary) errors which would need to be fixed using ugly preprocessor statements like '#if defined(FOO) && FOO'. -- Sebastian Harl git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1557 a5681a0c-68f1-0310-ab6d-d61299d08faa --- bindings/ruby/extconf.rb | 2 ++ bindings/ruby/main.c | 13 +++++++++++-- bindings/tcl/Makefile.am | 1 + bindings/tcl/tclrrd.c | 34 +++++++++++++++++++++------------- configure.ac | 15 +++++++++++++++ src/Makefile.am | 4 +++- src/rrd_client.c | 2 +- src/rrd_dump.c | 3 +-- src/rrd_gfx.c | 2 +- src/rrd_open.c | 6 +++--- src/rrd_xport.c | 2 +- 11 files changed, 60 insertions(+), 24 deletions(-) diff --git a/bindings/ruby/extconf.rb b/bindings/ruby/extconf.rb index 2045e5a..8f0c67d 100644 --- a/bindings/ruby/extconf.rb +++ b/bindings/ruby/extconf.rb @@ -3,6 +3,8 @@ require 'mkmf' +$CFLAGS += '-Wall' + if /linux/ =~ RUBY_PLATFORM $LDFLAGS += '-Wl,--rpath -Wl,$(EPREFIX)/lib' elsif /solaris/ =~ RUBY_PLATFORM diff --git a/bindings/ruby/main.c b/bindings/ruby/main.c index d2a7ace..d18b905 100644 --- a/bindings/ruby/main.c +++ b/bindings/ruby/main.c @@ -4,6 +4,7 @@ #include #include +#include #include "../../src/rrd_tool.h" typedef struct string_arr_t { @@ -19,6 +20,11 @@ typedef int ( int argc, char **argv); +typedef rrd_info_t *( + *RRDINFOFUNC) ( + int argc, + char **argv); + #define RRD_CHECK_ERROR \ if (rrd_test_error()) \ rb_raise(rb_eRRDError, rrd_get_error()); \ @@ -142,7 +148,7 @@ VALUE rb_rrd_update( /* Calls Returning Data via the Info Interface */ VALUE rb_rrd_infocall( - RRDFUNC func, + RRDINFOFUNC func, VALUE args) { string_arr a; @@ -173,9 +179,12 @@ VALUE rb_rrd_infocall( case RD_I_STR: rb_hash_aset(result, key, rb_str_new2(data->value.u_str)); break; + case RD_I_INT: + rb_hash_aset(result, key, INT2FIX(data->value.u_int)); + break; case RD_I_BLO: rb_hash_aset(result, key, - rb_str_new(data->value.u_blo.ptr, + rb_str_new((char *)data->value.u_blo.ptr, data->value.u_blo.size)); break; } diff --git a/bindings/tcl/Makefile.am b/bindings/tcl/Makefile.am index 34f4077..c0e8b0f 100644 --- a/bindings/tcl/Makefile.am +++ b/bindings/tcl/Makefile.am @@ -4,6 +4,7 @@ EXTRA_DIST = README tclrrd.c VERSION = @VERSION@ AM_CFLAGS = @CFLAGS@ +### no including this by default @WERROR@ TCL_PREFIX = @TCL_PREFIX@ TCL_SHLIB_LD = @TCL_SHLIB_LD@ diff --git a/bindings/tcl/tclrrd.c b/bindings/tcl/tclrrd.c index d4593bb..7f604d9 100644 --- a/bindings/tcl/tclrrd.c +++ b/bindings/tcl/tclrrd.c @@ -97,7 +97,7 @@ static void getopt_squieeze( /* Thread-safe version */ static int Rrd_Create( - ClientData clientData, + ClientData __attribute__((unused)) clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[]) @@ -186,7 +186,8 @@ static int Rrd_Create( return TCL_ERROR; } - rrd_create_r(argv2[1], pdp_step, last_up, argc - 2, argv2 + 2); + rrd_create_r(argv2[1], pdp_step, last_up, argc - 2, + (const char **)argv2 + 2); getopt_cleanup(argc, argv2); @@ -204,7 +205,7 @@ static int Rrd_Create( /* Thread-safe version */ static int Rrd_Dump( - ClientData clientData, + ClientData __attribute__((unused)) clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[]) @@ -233,7 +234,7 @@ static int Rrd_Dump( /* Thread-safe version */ static int Rrd_Last( - ClientData clientData, + ClientData __attribute__((unused)) clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[]) @@ -264,7 +265,7 @@ static int Rrd_Last( /* Thread-safe version */ static int Rrd_Update( - ClientData clientData, + ClientData __attribute__((unused)) clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[]) @@ -319,7 +320,7 @@ static int Rrd_Update( return TCL_ERROR; } - rrd_update_r(argv2[1], template, argc - 2, argv2 + 2); + rrd_update_r(argv2[1], template, argc - 2, (const char **)argv2 + 2); if (template != NULL) { free(template); @@ -337,7 +338,7 @@ static int Rrd_Update( } static int Rrd_Lastupdate( - ClientData clientData, + ClientData __attribute__((unused)) clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[]) @@ -350,8 +351,15 @@ static int Rrd_Lastupdate( Tcl_Obj *listPtr; unsigned long ds_cnt, i; + /* TODO: support for rrdcached */ + if (argc != 2) { + Tcl_AppendResult(interp, "RRD Error: needs a single rrd filename", + (char *) NULL); + return TCL_ERROR; + } + argv2 = getopt_init(argc, argv); - if (rrd_lastupdate(argc - 1, argv2, &last_update, + if (rrd_lastupdate_r(argv2[1], &last_update, &ds_cnt, &ds_namv, &last_ds) == 0) { listPtr = Tcl_GetObjResult(interp); for (i = 0; i < ds_cnt; i++) { @@ -379,7 +387,7 @@ static int Rrd_Lastupdate( } static int Rrd_Fetch( - ClientData clientData, + ClientData __attribute__((unused)) clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[]) @@ -424,7 +432,7 @@ static int Rrd_Fetch( static int Rrd_Graph( - ClientData clientData, + ClientData __attribute__((unused)) clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[]) @@ -534,7 +542,7 @@ static int Rrd_Graph( static int Rrd_Tune( - ClientData clientData, + ClientData __attribute__((unused)) clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[]) @@ -558,7 +566,7 @@ static int Rrd_Tune( static int Rrd_Resize( - ClientData clientData, + ClientData __attribute__((unused)) clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[]) @@ -582,7 +590,7 @@ static int Rrd_Resize( static int Rrd_Restore( - ClientData clientData, + ClientData __attribute__((unused)) clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[]) diff --git a/configure.ac b/configure.ac index 1e3da86..2370f21 100644 --- a/configure.ac +++ b/configure.ac @@ -138,6 +138,21 @@ AC_PROG_LIBTOOL dnl Try to detect/use GNU features CFLAGS="$CFLAGS -D_GNU_SOURCE" +dnl check for -Werror separatly +dnl (quite a few autotool checks don't work with -Werror; also, the +dnl check for -Werror fails after checking and adding the other flags) +AC_CACHE_CHECK([if gcc likes the -Werror flag], rd_cv_gcc_flag__Werror, + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[]], [[return 0 ]])], + [rd_cv_gcc_flag__Werror="yes"], + [rd_cv_gcc_flag__Werror="no"])]) +if test "x$rd_cv_gcc_flag__Werror" = "xyes"; then + WERROR="-Werror" +else + WERROR="" +fi +AC_SUBST(WERROR) + dnl which flags does the compiler support? if test "x$GCC" = "xyes"; then for flag in -fno-strict-aliasing -Wall -std=c99 -pedantic -Wundef -Wshadow -Wpointer-arith -Wcast-align -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline -Wold-style-definition -W; do diff --git a/src/Makefile.am b/src/Makefile.am index 420aeab..09bbe86 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,6 +12,8 @@ endif INCLUDES = -DLOCALEDIR="\"$(datadir)/locale\"" RRD_DEFAULT_FONT=@RRD_DEFAULT_FONT@ AM_CPPFLAGS = -DRRD_DEFAULT_FONT=\"$(RRD_DEFAULT_FONT)\" -DNUMVERS=@NUMVERS@ +AM_CFLAGS = @CFLAGS@ +## no including this by default @WERROR@ UPD_C_FILES = \ rrd_parsetime.c \ @@ -79,7 +81,7 @@ librrd_la_LDFLAGS += -export-symbols librrd.sym librrd_th_la_SOURCES = $(UPD_C_FILES) $(RRD_C_FILES) rrd_thread_safe.c librrd_th_la_DEPENDENCIES = librrd.sym -librrd_th_la_CFLAGS = $(MULTITHREAD_CFLAGS) +librrd_th_la_CFLAGS = $(AM_CFLAGS) $(MULTITHREAD_CFLAGS) librrd_th_la_LDFLAGS = $(MULTITHREAD_LDFLAGS) -version-info @LIBVERS@ librrd_th_la_LDFLAGS += -export-symbols librrd.sym librrd_th_la_LIBADD = $(ALL_LIBS) diff --git a/src/rrd_client.c b/src/rrd_client.c index 44d4d60..76fded0 100644 --- a/src/rrd_client.c +++ b/src/rrd_client.c @@ -741,7 +741,7 @@ void rrdc_stats_free (rrdc_stats_t *ret_stats) /* {{{ */ if (this->name != NULL) { - free (this->name); + free ((char *)this->name); this->name = NULL; } free (this); diff --git a/src/rrd_dump.c b/src/rrd_dump.c index a32f4fb..3f79a96 100644 --- a/src/rrd_dump.c +++ b/src/rrd_dump.c @@ -49,8 +49,7 @@ extern char *tzname[2]; #endif - -int rrd_dump_opt_r( +static int rrd_dump_opt_r( const char *filename, char *outname, int opt_noheader) diff --git a/src/rrd_gfx.c b/src/rrd_gfx.c index fa93861..421332f 100644 --- a/src/rrd_gfx.c +++ b/src/rrd_gfx.c @@ -124,7 +124,7 @@ static PangoLayout *gfx_prep_text( const char *text) { PangoLayout *layout = im->layout; - PangoFontDescription *pfd; + const PangoFontDescription *pfd; cairo_t *cr = im->cr; static double last_tabwidth = -1; diff --git a/src/rrd_open.c b/src/rrd_open.c index af91c7b..af08f90 100644 --- a/src/rrd_open.c +++ b/src/rrd_open.c @@ -321,9 +321,9 @@ void rrd_dontneed( rrd_t *rrd) { #if defined USE_MADVISE || defined HAVE_POSIX_FADVISE - unsigned long dontneed_start; - unsigned long rra_start; - unsigned long active_block; + off_t dontneed_start; + off_t rra_start; + off_t active_block; unsigned long i; ssize_t _page_size = sysconf(_SC_PAGESIZE); diff --git a/src/rrd_xport.c b/src/rrd_xport.c index caf23d0..225fba5 100644 --- a/src/rrd_xport.c +++ b/src/rrd_xport.c @@ -255,7 +255,7 @@ int rrd_xport_fn( ref_list[xport_counter++] = i; *step_list_ptr = im->gdes[im->gdes[i].vidx].step; printf("%s:%lu\n",im->gdes[i].legend,*step_list_ptr); - *step_list_ptr++; + step_list_ptr++; /* reserve room for one legend entry */ /* is FMT_LEG_LEN + 5 the correct size? */ if ((legend_list[j] = -- 2.11.0