Merge pull request #44 from adamdunkels/rime-nullptr-guard

Rime NULL pointer guards
This commit is contained in:
Nicolas Tsiftes 2012-11-24 11:14:02 -08:00
commit 63d205e4a2
6 changed files with 85 additions and 6 deletions

View file

@ -93,7 +93,9 @@ abc_input(struct channel *channel)
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1], rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
channel->channelno); channel->channelno);
if(c->u->recv) {
c->u->recv(c); c->u->recv(c);
}
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void

View file

@ -70,7 +70,9 @@ recv_from_abc(struct abc_conn *bc)
PRINTF("%d.%d: broadcast: from %d.%d\n", PRINTF("%d.%d: broadcast: from %d.%d\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1], rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
sender.u8[0], sender.u8[1]); sender.u8[0], sender.u8[1]);
if(c->u->recv) {
c->u->recv(c, &sender); c->u->recv(c, &sender);
}
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void

View file

@ -62,6 +62,9 @@
void void
collect_link_estimate_new(struct collect_link_estimate *le) collect_link_estimate_new(struct collect_link_estimate *le)
{ {
if(le == NULL) {
return;
}
le->num_estimates = 0; le->num_estimates = 0;
le->etx_accumulator = COLLECT_LINK_ESTIMATE_UNIT; le->etx_accumulator = COLLECT_LINK_ESTIMATE_UNIT;
} }
@ -69,6 +72,9 @@ collect_link_estimate_new(struct collect_link_estimate *le)
void void
collect_link_estimate_update_tx(struct collect_link_estimate *le, uint8_t tx) collect_link_estimate_update_tx(struct collect_link_estimate *le, uint8_t tx)
{ {
if(le == NULL) {
return;
}
if(tx == 0) { if(tx == 0) {
/* printf("ERROR tx == 0\n");*/ /* printf("ERROR tx == 0\n");*/
return; return;
@ -95,6 +101,9 @@ void
collect_link_estimate_update_tx_fail(struct collect_link_estimate *le, collect_link_estimate_update_tx_fail(struct collect_link_estimate *le,
uint8_t tx) uint8_t tx)
{ {
if(le == NULL) {
return;
}
collect_link_estimate_update_tx(le, tx * 2); collect_link_estimate_update_tx(le, tx * 2);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -107,6 +116,9 @@ collect_link_estimate_update_rx(struct collect_link_estimate *n)
uint16_t uint16_t
collect_link_estimate(struct collect_link_estimate *le) collect_link_estimate(struct collect_link_estimate *le)
{ {
if(le == NULL) {
return 0;
}
if(le->num_estimates == 0) { if(le->num_estimates == 0) {
return INITIAL_LINK_ESTIMATE * COLLECT_LINK_ESTIMATE_UNIT; return INITIAL_LINK_ESTIMATE * COLLECT_LINK_ESTIMATE_UNIT;
} }

View file

@ -129,6 +129,9 @@ collect_neighbor_list_find(struct collect_neighbor_list *neighbors_list,
const rimeaddr_t *addr) const rimeaddr_t *addr)
{ {
struct collect_neighbor *n; struct collect_neighbor *n;
if(neighbors_list == NULL) {
return NULL;
}
for(n = list_head(neighbors_list->list); n != NULL; n = list_item_next(n)) { for(n = list_head(neighbors_list->list); n != NULL; n = list_item_next(n)) {
if(rimeaddr_cmp(&n->addr, addr)) { if(rimeaddr_cmp(&n->addr, addr)) {
return n; return n;
@ -148,6 +151,10 @@ collect_neighbor_list_add(struct collect_neighbor_list *neighbors_list,
return 0; return 0;
} }
if(neighbors_list == NULL) {
return 0;
}
PRINTF("collect_neighbor_add: adding %d.%d\n", addr->u8[0], addr->u8[1]); PRINTF("collect_neighbor_add: adding %d.%d\n", addr->u8[0], addr->u8[1]);
/* Check if the collect_neighbor is already on the list. */ /* Check if the collect_neighbor is already on the list. */
@ -219,6 +226,10 @@ collect_neighbor_list_add(struct collect_neighbor_list *neighbors_list,
list_t list_t
collect_neighbor_list(struct collect_neighbor_list *neighbors_list) collect_neighbor_list(struct collect_neighbor_list *neighbors_list)
{ {
if(neighbors_list == NULL) {
return NULL;
}
return neighbors_list->list; return neighbors_list->list;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -226,7 +237,13 @@ void
collect_neighbor_list_remove(struct collect_neighbor_list *neighbors_list, collect_neighbor_list_remove(struct collect_neighbor_list *neighbors_list,
const rimeaddr_t *addr) const rimeaddr_t *addr)
{ {
struct collect_neighbor *n = collect_neighbor_list_find(neighbors_list, addr); struct collect_neighbor *n;
if(neighbors_list == NULL) {
return;
}
n = collect_neighbor_list_find(neighbors_list, addr);
if(n != NULL) { if(n != NULL) {
list_remove(neighbors_list->list, n); list_remove(neighbors_list->list, n);
@ -245,6 +262,10 @@ collect_neighbor_list_best(struct collect_neighbor_list *neighbors_list)
best = NULL; best = NULL;
found = 0; found = 0;
if(neighbors_list == NULL) {
return NULL;
}
/* PRINTF("%d: ", node_id);*/ /* PRINTF("%d: ", node_id);*/
PRINTF("collect_neighbor_best: "); PRINTF("collect_neighbor_best: ");
@ -267,6 +288,10 @@ collect_neighbor_list_best(struct collect_neighbor_list *neighbors_list)
int int
collect_neighbor_list_num(struct collect_neighbor_list *neighbors_list) collect_neighbor_list_num(struct collect_neighbor_list *neighbors_list)
{ {
if(neighbors_list == NULL) {
return 0;
}
PRINTF("collect_neighbor_num %d\n", list_length(neighbors_list->list)); PRINTF("collect_neighbor_num %d\n", list_length(neighbors_list->list));
return list_length(neighbors_list->list); return list_length(neighbors_list->list);
} }
@ -277,6 +302,10 @@ collect_neighbor_list_get(struct collect_neighbor_list *neighbors_list, int num)
int i; int i;
struct collect_neighbor *n; struct collect_neighbor *n;
if(neighbors_list == NULL) {
return NULL;
}
PRINTF("collect_neighbor_get %d\n", num); PRINTF("collect_neighbor_get %d\n", num);
i = 0; i = 0;
@ -294,6 +323,10 @@ collect_neighbor_list_get(struct collect_neighbor_list *neighbors_list, int num)
void void
collect_neighbor_list_purge(struct collect_neighbor_list *neighbors_list) collect_neighbor_list_purge(struct collect_neighbor_list *neighbors_list)
{ {
if(neighbors_list == NULL) {
return;
}
while(list_head(neighbors_list->list) != NULL) { while(list_head(neighbors_list->list) != NULL) {
memb_free(&collect_neighbors_mem, list_pop(neighbors_list->list)); memb_free(&collect_neighbors_mem, list_pop(neighbors_list->list));
} }
@ -314,6 +347,9 @@ collect_neighbor_update_rtmetric(struct collect_neighbor *n, uint16_t rtmetric)
void void
collect_neighbor_tx_fail(struct collect_neighbor *n, uint16_t num_tx) collect_neighbor_tx_fail(struct collect_neighbor *n, uint16_t num_tx)
{ {
if(n == NULL) {
return;
}
collect_link_estimate_update_tx_fail(&n->le, num_tx); collect_link_estimate_update_tx_fail(&n->le, num_tx);
n->le_age = 0; n->le_age = 0;
n->age = 0; n->age = 0;
@ -322,6 +358,9 @@ collect_neighbor_tx_fail(struct collect_neighbor *n, uint16_t num_tx)
void void
collect_neighbor_tx(struct collect_neighbor *n, uint16_t num_tx) collect_neighbor_tx(struct collect_neighbor *n, uint16_t num_tx)
{ {
if(n == NULL) {
return;
}
collect_link_estimate_update_tx(&n->le, num_tx); collect_link_estimate_update_tx(&n->le, num_tx);
n->le_age = 0; n->le_age = 0;
n->age = 0; n->age = 0;
@ -330,6 +369,9 @@ collect_neighbor_tx(struct collect_neighbor *n, uint16_t num_tx)
void void
collect_neighbor_rx(struct collect_neighbor *n) collect_neighbor_rx(struct collect_neighbor *n)
{ {
if(n == NULL) {
return;
}
collect_link_estimate_update_rx(&n->le); collect_link_estimate_update_rx(&n->le);
n->age = 0; n->age = 0;
} }
@ -337,6 +379,9 @@ collect_neighbor_rx(struct collect_neighbor *n)
uint16_t uint16_t
collect_neighbor_link_estimate(struct collect_neighbor *n) collect_neighbor_link_estimate(struct collect_neighbor *n)
{ {
if(n == NULL) {
return 0;
}
if(collect_neighbor_is_congested(n)) { if(collect_neighbor_is_congested(n)) {
/* printf("Congested %d.%d, sould return %d, returning %d\n", /* printf("Congested %d.%d, sould return %d, returning %d\n",
n->addr.u8[0], n->addr.u8[1], n->addr.u8[0], n->addr.u8[1],
@ -351,24 +396,38 @@ collect_neighbor_link_estimate(struct collect_neighbor *n)
uint16_t uint16_t
collect_neighbor_rtmetric_link_estimate(struct collect_neighbor *n) collect_neighbor_rtmetric_link_estimate(struct collect_neighbor *n)
{ {
if(n == NULL) {
return 0;
}
return n->rtmetric + collect_link_estimate(&n->le); return n->rtmetric + collect_link_estimate(&n->le);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
uint16_t uint16_t
collect_neighbor_rtmetric(struct collect_neighbor *n) collect_neighbor_rtmetric(struct collect_neighbor *n)
{ {
if(n == NULL) {
return 0;
}
return n->rtmetric; return n->rtmetric;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
collect_neighbor_set_congested(struct collect_neighbor *n) collect_neighbor_set_congested(struct collect_neighbor *n)
{ {
if(n == NULL) {
return;
}
timer_set(&n->congested_timer, EXPECTED_CONGESTION_DURATION); timer_set(&n->congested_timer, EXPECTED_CONGESTION_DURATION);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
collect_neighbor_is_congested(struct collect_neighbor *n) collect_neighbor_is_congested(struct collect_neighbor *n)
{ {
if(n == NULL) {
return 0;
}
if(timer_expired(&n->congested_timer)) { if(timer_expired(&n->congested_timer)) {
return 0; return 0;
} else { } else {

View file

@ -814,8 +814,10 @@ handle_ack(struct collect_conn *tc)
chance that another parent will be chosen. */ chance that another parent will be chosen. */
if(msg.flags & ACK_FLAGS_CONGESTED) { if(msg.flags & ACK_FLAGS_CONGESTED) {
PRINTF("ACK flag indicated parent was congested.\n"); PRINTF("ACK flag indicated parent was congested.\n");
if(n != NULL) {
collect_neighbor_set_congested(n); collect_neighbor_set_congested(n);
collect_neighbor_tx(n, tc->max_rexmits * 2); collect_neighbor_tx(n, tc->max_rexmits * 2);
}
update_rtmetric(tc); update_rtmetric(tc);
} }
if((msg.flags & ACK_FLAGS_DROPPED) == 0) { if((msg.flags & ACK_FLAGS_DROPPED) == 0) {

View file

@ -72,8 +72,10 @@ recv_from_broadcast(struct broadcast_conn *broadcast, const rimeaddr_t *from)
packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[0], packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[0],
packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[1]); packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[1]);
if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &rimeaddr_node_addr)) { if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &rimeaddr_node_addr)) {
if(c->u->recv) {
c->u->recv(c, from); c->u->recv(c, from);
} }
}
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void