]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
warnings: fix warnings when everything possible is turned on
authorSami Kerola <kerolasa@iki.fi>
Tue, 4 Oct 2016 16:00:34 +0000 (17:00 +0100)
committerSami Kerola <kerolasa@iki.fi>
Tue, 11 Oct 2016 18:29:19 +0000 (19:29 +0100)
Tested with gcc (GCC) 6.2.1 20160830 and following options

CFLAGS="-O -fPIC -D_FORTIFY_SOURCE -W -Wabi -DANOTHER_BRICK_IN_THE -Wall
-Wattributes -Wbad-function-cast -Wbuiltin-macro-redefined -Wcast-align
-Wchar-subscripts -Wcoverage-mismatch -Wcpp -Wdeclaration-after-statement
-Wdeprecated -Wdeprecated-declarations -Wdisabled-optimization
-Wdiv-by-zero -Wendif-labels -Wextra -Wfloat-equal -Wformat-contains-nul
-Wformat-extra-args -Wformat-nonliteral -Wformat-security -Wformat-y2k
-Wformat-zero-length -Wformat=2 -Winit-self -Winvalid-pch -Wlogical-op
-Wmissing-declarations -Wmissing-include-dirs -Wmissing-noreturn
-Wmissing-prototypes -Wmultichar -Wnested-externs -Wno-format-nonliteral
-Wno-inline -Wno-logical-op -Wno-long-long -Wno-missing-field-initializers
-Wno-overlength-strings -Wno-sign-compare -Wno-unused-parameter
-Wno-unused-result -Wnormalized=nfc -Wold-style-definition -Woverflow
-Woverlength-strings -Wpacked -Wpacked-bitfield-compat -Wpointer-arith
-Wpointer-to-int-cast -Wpragmas -Wredundant-decls -Wshadow -Wsign-compare
-Wstrict-aliasing -Wstrict-aliasing=2 -Wstrict-prototypes
-Wsuggest-attribute=noreturn -Wsync-nand -Wtrampolines -Wtype-limits
-Wundef -Wuninitialized -Wunknown-pragmas -Wunused -Wunused-local-typedefs
-Wvla -Wvolatile-register-var -Wwrite-strings -fdata-sections
-fdiagnostics-show-option -ffunction-sections -fno-common -funit-at-a-time
-fvisibility=hidden -pipe" ./configure && make

asn.c
curses.c
display.c
gtk.c
mtr.c
net.c
report.c
select.c

diff --git a/asn.c b/asn.c
index 13ae0f81cea427b93eaed461856873b60a8472e6..7d721a2c414498843e471231da5941006b75964c 100644 (file)
--- a/asn.c
+++ b/asn.c
@@ -148,6 +148,10 @@ static char *ipinfo_lookup(const char *domain) {
 
 // originX.asn.cymru.com txtrec:    ASN | Route | Country | Registry | Allocated
 static char* split_txtrec(struct mtr_ctl *ctl, char *txt_rec) {
+    char* prev;
+    char* next;
+    int i = 0, j;
+
     if (!txt_rec)
        return NULL;
     if (iihash) {
@@ -159,9 +163,7 @@ static char* split_txtrec(struct mtr_ctl *ctl, char *txt_rec) {
         }
     }
 
-    char* prev = txt_rec;
-    char* next;
-    int i = 0, j;
+    prev = txt_rec;
 
     while ((next = strchr(prev, ITEMSEP)) && (i < ITEMSMAX)) {
         *next = '\0';
@@ -199,11 +201,13 @@ static void reverse_host6(struct in6_addr *addr, char *buff) {
 #endif
 
 static char *get_ipinfo(struct mtr_ctl *ctl, ip_t *addr){
-    if (!addr)
-        return NULL;
-
     char key[NAMELEN];
     char lookup_key[NAMELEN];
+    char *val = NULL;
+    ENTRY item;
+
+    if (!addr)
+        return NULL;
 
     if (ctl->af == AF_INET6) {
 #ifdef ENABLE_IPV6
@@ -222,13 +226,11 @@ static char *get_ipinfo(struct mtr_ctl *ctl, ip_t *addr){
             return NULL;
     }
 
-    char *val = NULL;
-    ENTRY item;
-
     if (iihash) {
+        ENTRY *found_item;
+
         DEB_syslog(LOG_INFO, ">> Search: %s", key);
         item.key = key;;
-        ENTRY *found_item;
         if ((found_item = hsearch(item, FIND))) {
             if (!(val = (*((items_t*)found_item->data))[ctl->ipinfo_no]))
                 val = (*((items_t*)found_item->data))[0];
index 8b012f01b516cabf4cd720dc3bf28c051b1b876a..aff0b67fa55a0219f87c908c3d753fb921930c0a 100644 (file)
--- a/curses.c
+++ b/curses.c
@@ -82,10 +82,12 @@ static void pwcenter(char *str)
 static char *format_number (int n, int w, char *buf)
 {
    // XXX todo: implement w != 5.. 
-   if (w != 5) return ("unimpl");
+   if (w != 5) {
+     snprintf (buf, w+1, "%s", "unimpl");
+     return (buf);
+   }
 
    if (n < 100000) {
-     snprintf (buf, w+1, "%5d", n);
      return buf;
    }
    if (n < 1000000) {
@@ -628,7 +630,8 @@ extern void mtr_curses_redraw(struct mtr_ctl *ctl)
 
   move(0, 0);
   attron(A_BOLD);
-  pwcenter("My traceroute  [v" PACKAGE_VERSION "]");
+  snprintf(buf, sizeof(buf), "%s%s%s", "My traceroute  [v", PACKAGE_VERSION, "]");
+  pwcenter(buf);
   attroff(A_BOLD);
 
   mvprintw(1, 0, "%s (%s)", ctl->LocalHostname, net_localaddr());
@@ -679,11 +682,13 @@ extern void mtr_curses_redraw(struct mtr_ctl *ctl)
   } else {
     char msg[80];
     int padding = 30;
+    int max_cols;
+
 #ifdef HAVE_IPINFO
     if (is_printii(ctl))
       padding += get_iiwidth(ctl->ipinfo_no);
 #endif
-    int max_cols = maxx<=SAVED_PINGS+padding ? maxx-padding : SAVED_PINGS;
+    max_cols = maxx <= SAVED_PINGS + padding ? maxx-padding : SAVED_PINGS;
     startstat = padding - 2;
 
     sprintf(msg, " Last %3d pings", max_cols);
@@ -719,16 +724,17 @@ extern void mtr_curses_redraw(struct mtr_ctl *ctl)
 
 extern void mtr_curses_open(struct mtr_ctl *ctl)
 {
+  int bg_col = 0;
+  int i;
+
   initscr();
   raw();
   noecho(); 
-  int bg_col = 0;
   start_color();
 #ifdef HAVE_USE_DEFAULT_COLORS
   if (use_default_colors() == OK)
     bg_col = -1;
 #endif
-  int i;
   for (i = 0; i < 8; i++)
       init_pair(i+1, i, bg_col);
 
index 9a762048d8c8bebdef296001715254508a07ae89..ed59a7e901f713ec16ea9599a6cebe53defdf77b 100644 (file)
--- a/display.c
+++ b/display.c
@@ -24,8 +24,6 @@
 
 #include "mtr.h"
 #include "display.h"
-#include "mtr-curses.h"
-#include "mtr-gtk.h"
 #include "report.h"
 #include "select.h"
 #include "raw.h"
diff --git a/gtk.c b/gtk.c
index e7b5183924f5b6a48d5bc45da582fecd2a83fd60..990f2b794b898607939f2e0cc9e6eff85895913a 100644 (file)
--- a/gtk.c
+++ b/gtk.c
@@ -35,6 +35,7 @@
 #include "dns.h"
 #include "asn.h"
 #include "mtr-gtk.h"
+#include "utils.h"
 
 #include "img/mtr_icon.xpm"
 #endif
@@ -52,10 +53,11 @@ static GtkWidget *main_window;
 
 static void gtk_add_ping_timeout (struct mtr_ctl *ctl)
 {
+  int dt;
+
   if(gtk_toggle_button_get_active((GtkToggleButton *)Pause_Button)){
     return;
   }
-  int dt;
   dt = calc_deltatime (ctl->WaitTime);
   gtk_redraw(ctl);
   ping_timeout_timer = g_timeout_add(dt / 1000, gtk_ping, ctl);
@@ -560,15 +562,15 @@ static void Window_fill(struct mtr_ctl *ctl, GtkWidget *Window)
 extern void gtk_open(struct mtr_ctl *ctl)
 {
   GdkPixbuf *icon;
-
-  int argc;
+  int argc = 1;
   char *args[2];
   char **argv;
-  argc = 1;
+
   argv = args;
-  argv[0] = "";
+  argv[0] = xstrdup("");
   argv[1] = NULL;
   gtk_do_init(&argc, &argv);
+  free(argv[0]);
 
   icon = gdk_pixbuf_new_from_xpm_data((const char**)mtr_icon);
   gtk_window_set_default_icon(icon);
diff --git a/mtr.c b/mtr.c
index 0acb6583bbb9c007816f3852c42a8d7ec8c89b12..845d1c5721f2127c07a480599b1cca33c802e632 100644 (file)
--- a/mtr.c
+++ b/mtr.c
@@ -332,7 +332,7 @@ static void parse_arg (struct mtr_ctl *ctl, int argc, char **argv)
 #endif
     { NULL, 0, NULL, 0 }
   };
-  static const size_t num_options = sizeof(long_options) / sizeof(struct option);
+  enum { num_options = sizeof(long_options) / sizeof(struct option) };
   char short_options[num_options * 2];
   size_t n, p;
 
@@ -592,12 +592,11 @@ static void parse_arg (struct mtr_ctl *ctl, int argc, char **argv)
 
 static void parse_mtr_options (struct mtr_ctl *ctl, char *string)
 {
-  int argc;
+  int argc = 1;
   char *argv[128], *p;
 
   if (!string) return;
-
-  argv[0] = "mtr";
+  argv[0] = xstrdup(PACKAGE_NAME);
   argc = 1;
   p = strtok (string, " \t");
   while (p != NULL && ((size_t) argc < (sizeof(argv)/sizeof(argv[0])))) {
@@ -609,6 +608,7 @@ static void parse_mtr_options (struct mtr_ctl *ctl, char *string)
   }
 
   parse_arg (ctl, argc, argv);
+  free(argv[0]);
   optind = 0;
 }
 
@@ -632,6 +632,8 @@ extern int main(int argc, char **argv)
 #ifdef ENABLE_IPV6
   struct sockaddr_in6 * sa6;
 #endif
+  time_t now;
+  names_t *head;
   struct mtr_ctl ctl;
   memset(&ctl, 0, sizeof(ctl));
   /* initialize non-null values */
@@ -693,11 +695,9 @@ extern int main(int argc, char **argv)
     error(EXIT_FAILURE, 0, "Couldn't determine raw socket type");
   }
 
-  time_t now = time(NULL);
-
   if (!names) append_to_names ("localhost"); // default: localhost. 
 
-  names_t* head = names;
+  head = names;
   while (names != NULL) {
 
     ctl.Hostname = names->name;
@@ -792,6 +792,7 @@ extern int main(int argc, char **argv)
       display_loop(&ctl);
 
       net_end_transit();
+      now = time(NULL);
       display_close(&ctl, now);
     unlock(stdout);
 
diff --git a/net.c b/net.c
index 761b956915dc135d89af5697d26ceb849f2873ae..c27117818d8846e1c0c204118dc5753c4a25624b 100644 (file)
--- a/net.c
+++ b/net.c
@@ -258,6 +258,10 @@ static int udp_checksum(struct mtr_ctl *ctl, void *pheader, void *udata,
   size_t tsize = psize + dsize;
   char *csumpacket;
   int ret;
+  struct UDPv4PHeader *prepend;
+  struct UDPv4PHeader *udppheader;
+  struct UDPHeader *content;
+  struct UDPHeader *udpdata;
 
   csumpacket = xmalloc(tsize);
   memset(csumpacket, (unsigned char) abs(ctl->bitpattern), tsize);
@@ -266,16 +270,16 @@ static int udp_checksum(struct mtr_ctl *ctl, void *pheader, void *udata,
     csumpacket[psize + sizeof(struct UDPHeader) + 1] = 0;
   }
 
-  struct UDPv4PHeader *prepend = (struct UDPv4PHeader *) csumpacket;
-  struct UDPv4PHeader *udppheader = (struct UDPv4PHeader *) pheader;
+  prepend = (struct UDPv4PHeader *) csumpacket;
+  udppheader = (struct UDPv4PHeader *) pheader;
   prepend->saddr = udppheader->saddr;
   prepend->daddr = udppheader->daddr;
   prepend->zero = 0;
   prepend->protocol = udppheader->protocol;
   prepend->len = udppheader->len;
 
-  struct UDPHeader *content = (struct UDPHeader *)(csumpacket + psize);
-  struct UDPHeader *udpdata = (struct UDPHeader *) udata;
+  content = (struct UDPHeader *)(csumpacket + psize);
+  udpdata = (struct UDPHeader *) udata;
   content->srcport = udpdata->srcport;
   content->dstport = udpdata->dstport;
   content->length = udpdata->length;
@@ -550,18 +554,6 @@ static void net_send_sctp(struct mtr_ctl *ctl, int index)
 /*  Attempt to find the host at a particular number of hops away  */
 static void net_send_query(struct mtr_ctl *ctl, int index)
 {
-  if (ctl->mtrtype == IPPROTO_TCP) {
-    net_send_tcp(ctl, index);
-    return;
-  }
-  
-#ifdef HAS_SCTP
-  if (ctl->mtrtype == IPPROTO_SCTP) {
-    net_send_sctp(ctl, index);
-    return;
-  }
-#endif
-
   /*ok  char packet[sizeof(struct IPHeader) + sizeof(struct ICMPHeader)];*/
   char packet[MAXPACKET];
   struct IPHeader *ip = (struct IPHeader *) packet;
@@ -569,19 +561,29 @@ static void net_send_query(struct mtr_ctl *ctl, int index)
   struct UDPHeader *udp = NULL;
   struct UDPv4PHeader *udpp = NULL;
   uint16_t checksum_result;
-
   /*ok  int packetsize = sizeof(struct IPHeader) + sizeof(struct ICMPHeader) + datasize;*/
   int rv;
   static int first=1;
   int ttl, iphsize = 0, echotype = 0, salen = 0;
-
-  ttl = index + 1;
-
 #ifdef ENABLE_IPV6
   /* offset for ipv6 checksum calculation */
   int offset = 6;
 #endif
 
+  if (ctl->mtrtype == IPPROTO_TCP) {
+    net_send_tcp(ctl, index);
+    return;
+  }
+
+#ifdef HAS_SCTP
+  if (ctl->mtrtype == IPPROTO_SCTP) {
+    net_send_sctp(ctl, index);
+    return;
+  }
+#endif
+
+  ttl = index + 1;
+
   if ( packetsize < MINPACKET ) packetsize = MINPACKET;
   if ( packetsize > MAXPACKET ) packetsize = MAXPACKET;
   if ( ctl->mtrtype == IPPROTO_UDP && ctl->remoteport && packetsize < (MINPACKET + 2)) {
index 79bd9469ddfd2244fc6f33b810cd1bdec10cf83d..2f6662f2a7682b9a08a8374f86068707a741d81d 100644 (file)
--- a/report.c
+++ b/report.c
@@ -77,6 +77,10 @@ extern void report_close(struct mtr_ctl *ctl)
   char fmt[16];
   size_t len=0;
   size_t len_hosts = 33;
+#ifdef HAVE_IPINFO
+  int len_tmp = len_hosts;
+  const size_t iiwidth_len = get_iiwidth_len();
+#endif
 
   if (ctl->reportwide)
   {
@@ -94,8 +98,6 @@ extern void report_close(struct mtr_ctl *ctl)
   }
   
 #ifdef HAVE_IPINFO
-  int len_tmp = len_hosts;
-  const size_t iiwidth_len = get_iiwidth_len();
   if (ctl->ipinfo_no >= 0 && iiwidth_len) {
     ctl->ipinfo_no %= iiwidth_len;
     if (ctl->reportwide) {
@@ -160,9 +162,9 @@ extern void report_close(struct mtr_ctl *ctl)
 
     /* z is starting at 1 because addrs[0] is the same that addr */
     for (z = 1; z < MAXPATH ; z++) {
+      int found = 0;
       addr2 = net_addrs(at, z);
       mplss = net_mplss(at, z);
-      int found = 0;
       if ((addrcmp ((void *) &ctl->unspec_addr, (void *) addr2, ctl->af)) == 0)
         break;
       for (w = 0; w < z; w++)
@@ -287,6 +289,8 @@ extern void json_close(struct mtr_ctl *ctl)
     printf("      \"count\": \"%d\",\n", at+1);
     printf("      \"host\": \"%s\",\n", name);
     for( i=0; i<MAXFLD; i++ ) {
+      const char *format;
+
       j = ctl->fld_index[ctl->fld_active[i]];
 
       /* Commas */
@@ -299,7 +303,6 @@ extern void json_close(struct mtr_ctl *ctl)
       if (j <= 0) continue; // Field nr 0, " " shouldn't be printed in this method.
 
       /* Format value */
-      const char *format;
       format = data_fields[j].format;
       if( strchr(format, 'f') ) {
         format = "%.2f";
@@ -368,13 +371,14 @@ extern void xml_close(struct mtr_ctl *ctl)
 
     printf("    <HUB COUNT=\"%d\" HOST=\"%s\">\n", at+1, name);
     for( i=0; i<MAXFLD; i++ ) {
+      const char *title;
+
       j = ctl->fld_index[ctl->fld_active[i]];
       if (j <= 0) continue; // Field nr 0, " " shouldn't be printed in this method. 
 
       snprintf(name, sizeof(name), "%s%s%s", "        <%s>", data_fields[j].format, "</%s>\n");
 
       /* XML doesn't allow "%" in tag names, rename Loss% to just Loss */
-      const char *title;
       title = data_fields[j].title;
       if( strcmp(data_fields[j].title, "Loss%") == 0 ) {
                title = "Loss";
index 4bf3c3da53b0fe46f6693cf496fd11aa6eabceb5..745faade667283fe2690631bc10f822fbc53b602 100644 (file)
--- a/select.c
+++ b/select.c
@@ -39,6 +39,7 @@
 #include "net.h"
 #include "asn.h"
 #include "display.h"
+#include "select.h"
 
 static double dnsinterval;
 static struct timeval intervaltime;