[Olsr-dev] [PATCH v1 07/14] sgw: fix GCC 6 warnings

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


From: Ferry Huberts <(spam-protected)>

src/gateway.c: In function ‘takeDownExpensiveGateways’:
src/gateway.c:701:17: error: potential null pointer dereference [-Werror=null-dereference]
     if (worst_gw->gw->path_cost < current_gw_cost_boundary) {
         ~~~~~~~~^~~~

Signed-off-by: Ferry Huberts <(spam-protected)>
---
 src/gateway.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/gateway.c b/src/gateway.c
index 3e5b233..5338ac0 100644
--- a/src/gateway.c
+++ b/src/gateway.c
@@ -688,6 +688,11 @@ static void takeDownExpensiveGateways(struct gw_list * gw_list, bool ipv4, struc
   while (gw_list->count > 1) {
     /* get the worst gateway */
     struct gw_container_entry * worst_gw = olsr_gw_list_get_worst_entry(gw_list);
+    assert(worst_gw);
+
+    if (!worst_gw) {
+      return;
+    }
 
     /* exit when it's the current gateway */
     if (worst_gw == current_gw) {
@@ -698,7 +703,7 @@ static void takeDownExpensiveGateways(struct gw_list * gw_list, bool ipv4, struc
      * exit when it (and further ones; the list is sorted on costs) has lower
      * costs than the boundary costs
      */
-    if (worst_gw->gw->path_cost < current_gw_cost_boundary) {
+    if (worst_gw->gw && (worst_gw->gw->path_cost < current_gw_cost_boundary)) {
       return;
     }
 
-- 
2.5.0




More information about the Olsr-dev mailing list