From 70f9f075a0877074ac4e8492f7b78fd30d8b232f Mon Sep 17 00:00:00 2001 From: adamdunkels Date: Mon, 10 Jan 2011 15:08:52 +0000 Subject: [PATCH] Safeguard against NULL arguments --- core/net/rime/collect-neighbor.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/net/rime/collect-neighbor.c b/core/net/rime/collect-neighbor.c index 7e91ce855..b63d2106e 100644 --- a/core/net/rime/collect-neighbor.c +++ b/core/net/rime/collect-neighbor.c @@ -33,7 +33,7 @@ * * This file is part of the Contiki operating system. * - * $Id: collect-neighbor.c,v 1.9 2011/01/09 21:20:05 adamdunkels Exp $ + * $Id: collect-neighbor.c,v 1.10 2011/01/10 15:08:52 adamdunkels Exp $ */ /** @@ -144,6 +144,11 @@ collect_neighbor_list_add(struct collect_neighbor_list *neighbors_list, { struct collect_neighbor *n; + if(addr == NULL) { + PRINTF("collect_neighbor_list_add: attempt to add NULL addr\n"); + return 0; + } + PRINTF("collect_neighbor_add: adding %d.%d\n", addr->u8[0], addr->u8[1]); /* Check if the collect_neighbor is already on the list. */ @@ -195,8 +200,10 @@ collect_neighbor_list_add(struct collect_neighbor_list *neighbors_list, if(nrtmetric < worst_rtmetric) { n = worst_neighbor; } - PRINTF("collect_neighbor_add: not on list, not allocated, recycling %d.%d\n", - n->addr.u8[0], n->addr.u8[1]); + if(n != NULL) { + PRINTF("collect_neighbor_add: not on list, not allocated, recycling %d.%d\n", + n->addr.u8[0], n->addr.u8[1]); + } } if(n != NULL) {