[Olsr-dev] [PATCH v1 06/14] link_set: fix GCC 6 warnings

Ferry Huberts (spam-protected)
Wed Feb 24 00:46:15 CET 2016


From: Ferry Huberts <(spam-protected)>

src/link_set.c: In function ‘update_link_entry’:
src/link_set.c:335:24: error: potential null pointer dereference [-Werror=null-dereference]
   for (mult = cfg_inter->cnf->lq_mult; mult != NULL; mult = mult->next) {
               ~~~~~~~~~^~~~~

Signed-off-by: Ferry Huberts <(spam-protected)>
---
 src/link_set.c | 37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/src/link_set.c b/src/link_set.c
index 7e8432f..d44b13e 100644
--- a/src/link_set.c
+++ b/src/link_set.c
@@ -309,8 +309,8 @@ get_best_link_to_neighbor(const union olsr_ip_addr *remote)
 static void
 set_loss_link_multiplier(struct link_entry *entry)
 {
-  struct interface_olsr *inter;
-  struct olsr_if *cfg_inter;
+  struct interface_olsr *inter = NULL;
+  struct olsr_if *cfg_inter = NULL;
   struct olsr_lq_mult *mult;
   uint32_t val = 0;
   union olsr_ip_addr null_addr;
@@ -320,26 +320,29 @@ set_loss_link_multiplier(struct link_entry *entry)
   assert(entry->if_name);
   inter = if_ifwithname(entry->if_name);
 
-  /* find the interface configuration for the interface */
-  for (cfg_inter = olsr_cnf->interfaces; cfg_inter; cfg_inter = cfg_inter->next) {
-    if (cfg_inter->interf == inter) {
-      break;
+  if (!inter) {
+    /* find the interface configuration for the interface */
+    for (cfg_inter = olsr_cnf->interfaces; cfg_inter; cfg_inter = cfg_inter->next) {
+      if (cfg_inter->interf == inter) {
+        break;
+      }
     }
   }
-  assert(cfg_inter);
 
-  /* create a null address for comparison */
-  memset(&null_addr, 0, sizeof(union olsr_ip_addr));
+  if (cfg_inter) {
+    /* create a null address for comparison */
+    memset(&null_addr, 0, sizeof(union olsr_ip_addr));
 
-  /* loop through the multiplier entries */
-  for (mult = cfg_inter->cnf->lq_mult; mult != NULL; mult = mult->next) {
+    /* loop through the multiplier entries */
+    for (mult = cfg_inter->cnf->lq_mult; mult != NULL; mult = mult->next) {
 
-    /*
-     * use the default multiplier only if there isn't any entry that
-     * has a matching IP address.
-     */
-    if ((ipequal(&mult->addr, &null_addr) && val == 0) || ipequal(&mult->addr, &entry->neighbor_iface_addr)) {
-      val = mult->value;
+      /*
+       * use the default multiplier only if there isn't any entry that
+       * has a matching IP address.
+       */
+      if ((ipequal(&mult->addr, &null_addr) && val == 0) || ipequal(&mult->addr, &entry->neighbor_iface_addr)) {
+        val = mult->value;
+      }
     }
   }
 
-- 
2.5.0




More information about the Olsr-dev mailing list