[rrd-developers] [PATCH] Use -Werror.

Sebastian Harl sh at tokkee.org
Wed Oct 1 16:57:39 CEST 2008


This patch adds -Werror to the CFLAGS of all parts of rrdtool. All issues that
were identified by that have been fixed. This includes 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'.
---
 program/bindings/lua/Makefile.lua |    2 +-
 program/bindings/ruby/extconf.rb  |    2 ++
 program/bindings/ruby/main.c      |   13 +++++++++++--
 program/bindings/tcl/Makefile.am  |    2 +-
 program/bindings/tcl/tclrrd.c     |   34 +++++++++++++++++++++-------------
 program/configure.ac              |   15 +++++++++++++++
 program/src/Makefile.am           |    3 ++-
 program/src/rrd_client.c          |    2 +-
 program/src/rrd_dump.c            |    3 +--
 program/src/rrd_gfx.c             |    2 +-
 program/src/rrd_open.c            |    6 +++---
 program/src/rrd_xport.c           |    2 +-
 12 files changed, 60 insertions(+), 26 deletions(-)

diff --git a/program/bindings/lua/Makefile.lua b/program/bindings/lua/Makefile.lua
index 08be1cc..1c16bb8 100644
--- a/program/bindings/lua/Makefile.lua
+++ b/program/bindings/lua/Makefile.lua
@@ -84,7 +84,7 @@ PIC=-fPIC
 #PIC=-fpic
 
 # Compilation directives
-OPTIONS= -O3 -Wall ${PIC} -fomit-frame-pointer -pedantic-errors -W -Waggregate-return -Wcast-align -Wmissing-prototypes -Wnested-externs -Wshadow -Wwrite-strings
+OPTIONS= -O3 -Wall -Werror ${PIC} -fomit-frame-pointer -pedantic-errors -W -Waggregate-return -Wcast-align -Wmissing-prototypes -Wnested-externs -Wshadow -Wwrite-strings
 LIBS= $(RRD_LIB_DIR) $(LUA_LFLAGS) -lm
 CFLAGS= $(OPTIONS) $(LUA_CFLAGS) $(RRD_CFLAGS) -DLIB_VERSION=\"$(LIB_VERSION)\"
 #CC= gcc
diff --git a/program/bindings/ruby/extconf.rb b/program/bindings/ruby/extconf.rb
index 2045e5a..6468de1 100644
--- a/program/bindings/ruby/extconf.rb
+++ b/program/bindings/ruby/extconf.rb
@@ -3,6 +3,8 @@
 
 require 'mkmf'
 
+$CFLAGS += '-Wall -Werror'
+
 if /linux/ =~ RUBY_PLATFORM
    $LDFLAGS += '-Wl,--rpath -Wl,$(EPREFIX)/lib'
 elsif /solaris/ =~ RUBY_PLATFORM
diff --git a/program/bindings/ruby/main.c b/program/bindings/ruby/main.c
index d2a7ace..d18b905 100644
--- a/program/bindings/ruby/main.c
+++ b/program/bindings/ruby/main.c
@@ -4,6 +4,7 @@
 
 #include <unistd.h>
 #include <ruby.h>
+#include <math.h>
 #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/program/bindings/tcl/Makefile.am b/program/bindings/tcl/Makefile.am
index 34f4077..9b9ce20 100644
--- a/program/bindings/tcl/Makefile.am
+++ b/program/bindings/tcl/Makefile.am
@@ -3,7 +3,7 @@ EXTRA_DIST = README tclrrd.c
 
 VERSION = @VERSION@
 
-AM_CFLAGS = @CFLAGS@
+AM_CFLAGS = @CFLAGS@ @WERROR@
 
 TCL_PREFIX = @TCL_PREFIX@
 TCL_SHLIB_LD = @TCL_SHLIB_LD@
diff --git a/program/bindings/tcl/tclrrd.c b/program/bindings/tcl/tclrrd.c
index d4593bb..7f604d9 100644
--- a/program/bindings/tcl/tclrrd.c
+++ b/program/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/program/configure.ac b/program/configure.ac
index 1e3da86..2370f21 100644
--- a/program/configure.ac
+++ b/program/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/program/src/Makefile.am b/program/src/Makefile.am
index 420aeab..78fcef7 100644
--- a/program/src/Makefile.am
+++ b/program/src/Makefile.am
@@ -12,6 +12,7 @@ endif
 INCLUDES = -DLOCALEDIR="\"$(datadir)/locale\""
 RRD_DEFAULT_FONT=@RRD_DEFAULT_FONT@
 AM_CPPFLAGS = -DRRD_DEFAULT_FONT=\"$(RRD_DEFAULT_FONT)\" -DNUMVERS=@NUMVERS@
+AM_CFLAGS = @CFLAGS@ @WERROR@
 
 UPD_C_FILES =		\
 	rrd_parsetime.c	\
@@ -79,7 +80,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/program/src/rrd_client.c b/program/src/rrd_client.c
index 44d4d60..76fded0 100644
--- a/program/src/rrd_client.c
+++ b/program/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/program/src/rrd_dump.c b/program/src/rrd_dump.c
index a32f4fb..3f79a96 100644
--- a/program/src/rrd_dump.c
+++ b/program/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/program/src/rrd_gfx.c b/program/src/rrd_gfx.c
index fa93861..421332f 100644
--- a/program/src/rrd_gfx.c
+++ b/program/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/program/src/rrd_open.c b/program/src/rrd_open.c
index af91c7b..af08f90 100644
--- a/program/src/rrd_open.c
+++ b/program/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/program/src/rrd_xport.c b/program/src/rrd_xport.c
index caf23d0..225fba5 100644
--- a/program/src/rrd_xport.c
+++ b/program/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] =
-- 
1.6.0.1.216.g1b23a

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.oetiker.ch/pipermail/rrd-developers/attachments/20081001/ccfa7f9b/attachment-0001.bin 


More information about the rrd-developers mailing list