[Olsr-dev] [PATCH v1 06/12] Makefile: WARNINGS: add -Wswitch-default

Ferry Huberts (spam-protected)
Tue May 29 15:59:35 CEST 2012


From: Ferry Huberts <(spam-protected)>

-Wswitch-default
  Warn whenever a "switch" statement does not have a "default" case.

Signed-off-by: Ferry Huberts <(spam-protected)>
---
 Makefile.inc                      |    1 +
 lib/nameservice/src/nameservice.c |    3 +++
 lib/p2pd/src/p2pd.c               |   20 +++++++++++---------
 lib/secure/src/olsrd_secure.c     |    3 ++-
 lib/tas/Makefile                  |    1 +
 lib/tas/src/http.c                |    2 ++
 src/build_msg.c                   |   20 ++++++++++++--------
 src/cfgparser/local.mk            |    2 +-
 src/hashing.c                     |    5 ++++-
 9 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/Makefile.inc b/Makefile.inc
index 541e9fb..4d4e35e 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -93,6 +93,7 @@ WARNINGS +=	-Wdouble-promotion
 WARNINGS +=	-Wformat-security
 WARNINGS +=	-Wformat-y2k
 WARNINGS +=	-Winit-self
+WARNINGS +=	-Wswitch-default
 # the following 2 do not work yet and need more work on it
 #WARNINGS +=	-Wconversion
 #WARNINGS +=	-Wredundant-decls
diff --git a/lib/nameservice/src/nameservice.c b/lib/nameservice/src/nameservice.c
index cc09646..53ad64b 100644
--- a/lib/nameservice/src/nameservice.c
+++ b/lib/nameservice/src/nameservice.c
@@ -448,6 +448,9 @@ remove_nonvalid_names_from_list(struct name_entry *my_list, int type)
   case NAME_LATLON:
     valid = is_latlon_wellformed(my_list->name);
     break;
+  default:
+	valid = false;
+	break;
   }
 
   if (!valid) {
diff --git a/lib/p2pd/src/p2pd.c b/lib/p2pd/src/p2pd.c
index 7fc6316..5263520 100644
--- a/lib/p2pd/src/p2pd.c
+++ b/lib/p2pd/src/p2pd.c
@@ -906,12 +906,6 @@ AddUdpDestPort(const char *value,
   // IPv4 broadcast or IPv6 multicast.
 
   switch (ip_version) {
-  case AF_INET:
-    res = inet_pton(AF_INET, destAddr, &addr4.sin_addr);
-    if (!is_broadcast(addr4) && !is_multicast(addr4)) {
-      OLSR_PRINTF(1,"WARNING: IPv4 address must be multicast or broadcast... ");
-    }
-    break;
   case AF_INET6:
     res = inet_pton(AF_INET6, destAddr, &addr6.sin6_addr);
     if (addr6.sin6_addr.s6_addr[0] != 0xFF) {
@@ -919,6 +913,13 @@ AddUdpDestPort(const char *value,
       return -1;
     }
     break;
+  case AF_INET:
+  default:
+    res = inet_pton(AF_INET, destAddr, &addr4.sin_addr);
+    if (!is_broadcast(addr4) && !is_multicast(addr4)) {
+      OLSR_PRINTF(1,"WARNING: IPv4 address must be multicast or broadcast... ");
+    }
+    break;
   }
   // Determine whether it is a valid IP address
   if (res == 0) {
@@ -935,14 +936,15 @@ AddUdpDestPort(const char *value,
 
   new->ip_version = ip_version;
   switch (ip_version) {
-  case AF_INET:
-    new->address.v4.s_addr = addr4.sin_addr.s_addr;
-    break;
   case AF_INET6:
     memcpy(&new->address.v6.s6_addr,
            &addr6.sin6_addr.s6_addr,
            sizeof(addr6.sin6_addr.s6_addr));
     break;
+  default:
+  case AF_INET:
+    new->address.v4.s_addr = addr4.sin_addr.s_addr;
+    break;
   }
   new->port = destPort;
   new->next = UdpDestPortList;
diff --git a/lib/secure/src/olsrd_secure.c b/lib/secure/src/olsrd_secure.c
index b83dc18..a2a046c 100644
--- a/lib/secure/src/olsrd_secure.c
+++ b/lib/secure/src/olsrd_secure.c
@@ -431,7 +431,8 @@ validate_packet(struct interface *olsr_if, const char *pck, int *size)
     case (SCHEME):
       goto one_checksum_SHA;    /* Ahhh... fix this */
       break;
-
+    default:
+    	break;
     }
     break;
 
diff --git a/lib/tas/Makefile b/lib/tas/Makefile
index abdff3e..c164dcf 100644
--- a/lib/tas/Makefile
+++ b/lib/tas/Makefile
@@ -65,6 +65,7 @@ $(PLUGIN_FULLNAME): $(OBJS) version-script.txt
 
 # this is not nice but there is no nicer solution
 src/lua/lapi.o src/lua/ltable.o:  CFLAGS += -Wno-cast-qual
+src/lua/ldebug.o src/lua/ldo.o src/lua/lbaselib.o src/lua/ldblib.o src/lua/lvm.o src/lua/lapi.o: CFLAGS += -Wno-switch-default
 
 install:	$(PLUGIN_FULLNAME)
 		$(STRIP) $(PLUGIN_FULLNAME)
diff --git a/lib/tas/src/http.c b/lib/tas/src/http.c
index 01a1a23..183c87a 100644
--- a/lib/tas/src/http.c
+++ b/lib/tas/src/http.c
@@ -1653,6 +1653,8 @@ serviceConn(struct connInfo *info)
       return -1;
 
     return 0;
+  default:
+	  return -1;
   }
 
   return 0;
diff --git a/src/build_msg.c b/src/build_msg.c
index ebca6b4..b10830d 100644
--- a/src/build_msg.c
+++ b/src/build_msg.c
@@ -135,10 +135,11 @@ queue_hello(struct hello_message * message, struct interface * ifp)
 #endif
 
   switch (olsr_cnf->ip_version) {
-  case (AF_INET):
-    return serialize_hello4(message, ifp);
   case (AF_INET6):
     return serialize_hello6(message, ifp);
+  case (AF_INET):
+  default:
+    return serialize_hello4(message, ifp);
   }
   return false;
 }
@@ -164,10 +165,11 @@ queue_tc(struct tc_message * message, struct interface * ifp)
 #endif
 
   switch (olsr_cnf->ip_version) {
-  case (AF_INET):
-    return serialize_tc4(message, ifp);
   case (AF_INET6):
     return serialize_tc6(message, ifp);
+  case (AF_INET):
+  default:
+    return serialize_tc4(message, ifp);
   }
   return false;
 }
@@ -188,10 +190,11 @@ queue_mid(struct interface * ifp)
 #endif
 
   switch (olsr_cnf->ip_version) {
-  case (AF_INET):
-    return serialize_mid4(ifp);
   case (AF_INET6):
     return serialize_mid6(ifp);
+  case (AF_INET):
+  default:
+    return serialize_mid4(ifp);
   }
   return false;
 }
@@ -211,10 +214,11 @@ queue_hna(struct interface * ifp)
 #endif
 
   switch (olsr_cnf->ip_version) {
-  case (AF_INET):
-    return serialize_hna4(ifp);
   case (AF_INET6):
     return serialize_hna6(ifp);
+  case (AF_INET):
+  default:
+    return serialize_hna4(ifp);
   }
   return false;
 }
diff --git a/src/cfgparser/local.mk b/src/cfgparser/local.mk
index b614a9f..0a3212a 100644
--- a/src/cfgparser/local.mk
+++ b/src/cfgparser/local.mk
@@ -60,7 +60,7 @@ $(C)oscan.c: $(C)oscan.lex $(C)Makefile
 
 # we need a dependency to generate oparse before we compile oscan.c
 $(C)oscan.o: $(C)oparse.c
-$(C)oscan.o: CFLAGS := $(filter-out -Wunreachable-code -Wsign-compare,$(CFLAGS)) -Wno-sign-compare
+$(C)oscan.o: CFLAGS := $(filter-out -Wunreachable-code -Wsign-compare,$(CFLAGS)) -Wno-sign-compare -Wno-switch-default
 # we need potentially another -I directory
 $(C)oscan.o: CPPFLAGS += $(if $(CFGDIR),-I$(CFGDIR)) -DYY_NO_INPUT
 
diff --git a/src/hashing.c b/src/hashing.c
index 28a0584..a283c72 100644
--- a/src/hashing.c
+++ b/src/hashing.c
@@ -125,7 +125,10 @@ jenkins_hash(const uint8_t * k, uint32_t length)
     /* no break */
   case 1:
     a += k[0];
-    /* no break */
+    break;
+
+  default:
+	  break;
   }
   __jhash_mix(a, b, c);
 
-- 
1.7.7.6





More information about the Olsr-dev mailing list