pud: fix getBestUplinkGateway
authorFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 22 Oct 2012 11:01:18 +0000 (13:01 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 22 Oct 2012 11:55:39 +0000 (13:55 +0200)
Coverity:
CID 739645 (#1 of 1): Explicit null dereferenced (FORWARD_NULL)
At (18): Passing null pointer "&gw_best->originator.v4" to function
         "ip4cmp(struct in_addr const *, struct in_addr const *)", which
         dereferences it.

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/pud/src/uplinkGateway.c

index 608072c..a00ecd1 100644 (file)
@@ -76,7 +76,7 @@ void getBestUplinkGateway(union olsr_ip_addr * bestGateway) {
 
                if (eval4 || eval6) {
                        unsigned long long gw_value = gw_speed(gw);
-                       if (gw_value > gw_best_value) {
+                       if (!gw_best || (gw_value > gw_best_value)) {
                                gw_best = gw;
                                gw_best_value = gw_value;
                        } else if (gw_value == gw_best_value) {