mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-22 10:30:13 +00:00
Added NULL pointer guards
This commit is contained in:
parent
0a8183d295
commit
0cd2f48d6e
@ -93,7 +93,9 @@ abc_input(struct channel *channel)
|
||||
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
|
||||
channel->channelno);
|
||||
|
||||
c->u->recv(c);
|
||||
if(c->u->recv) {
|
||||
c->u->recv(c);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
|
@ -70,7 +70,9 @@ recv_from_abc(struct abc_conn *bc)
|
||||
PRINTF("%d.%d: broadcast: from %d.%d\n",
|
||||
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
|
||||
sender.u8[0], sender.u8[1]);
|
||||
c->u->recv(c, &sender);
|
||||
if(c->u->recv) {
|
||||
c->u->recv(c, &sender);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
|
@ -62,6 +62,9 @@
|
||||
void
|
||||
collect_link_estimate_new(struct collect_link_estimate *le)
|
||||
{
|
||||
if(le == NULL) {
|
||||
return;
|
||||
}
|
||||
le->num_estimates = 0;
|
||||
le->etx_accumulator = COLLECT_LINK_ESTIMATE_UNIT;
|
||||
}
|
||||
@ -69,6 +72,9 @@ collect_link_estimate_new(struct collect_link_estimate *le)
|
||||
void
|
||||
collect_link_estimate_update_tx(struct collect_link_estimate *le, uint8_t tx)
|
||||
{
|
||||
if(le == NULL) {
|
||||
return;
|
||||
}
|
||||
if(tx == 0) {
|
||||
/* printf("ERROR tx == 0\n");*/
|
||||
return;
|
||||
@ -95,6 +101,9 @@ void
|
||||
collect_link_estimate_update_tx_fail(struct collect_link_estimate *le,
|
||||
uint8_t tx)
|
||||
{
|
||||
if(le == NULL) {
|
||||
return;
|
||||
}
|
||||
collect_link_estimate_update_tx(le, tx * 2);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
@ -107,6 +116,9 @@ collect_link_estimate_update_rx(struct collect_link_estimate *n)
|
||||
uint16_t
|
||||
collect_link_estimate(struct collect_link_estimate *le)
|
||||
{
|
||||
if(le == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if(le->num_estimates == 0) {
|
||||
return INITIAL_LINK_ESTIMATE * COLLECT_LINK_ESTIMATE_UNIT;
|
||||
}
|
||||
|
@ -129,6 +129,9 @@ collect_neighbor_list_find(struct collect_neighbor_list *neighbors_list,
|
||||
const rimeaddr_t *addr)
|
||||
{
|
||||
struct collect_neighbor *n;
|
||||
if(neighbors_list == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
for(n = list_head(neighbors_list->list); n != NULL; n = list_item_next(n)) {
|
||||
if(rimeaddr_cmp(&n->addr, addr)) {
|
||||
return n;
|
||||
@ -148,6 +151,10 @@ collect_neighbor_list_add(struct collect_neighbor_list *neighbors_list,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(neighbors_list == NULL) {
|
||||
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. */
|
||||
@ -219,6 +226,10 @@ collect_neighbor_list_add(struct collect_neighbor_list *neighbors_list,
|
||||
list_t
|
||||
collect_neighbor_list(struct collect_neighbor_list *neighbors_list)
|
||||
{
|
||||
if(neighbors_list == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return neighbors_list->list;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
@ -226,7 +237,13 @@ void
|
||||
collect_neighbor_list_remove(struct collect_neighbor_list *neighbors_list,
|
||||
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) {
|
||||
list_remove(neighbors_list->list, n);
|
||||
@ -245,6 +262,10 @@ collect_neighbor_list_best(struct collect_neighbor_list *neighbors_list)
|
||||
best = NULL;
|
||||
found = 0;
|
||||
|
||||
if(neighbors_list == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* PRINTF("%d: ", node_id);*/
|
||||
PRINTF("collect_neighbor_best: ");
|
||||
|
||||
@ -267,6 +288,10 @@ collect_neighbor_list_best(struct collect_neighbor_list *neighbors_list)
|
||||
int
|
||||
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));
|
||||
return list_length(neighbors_list->list);
|
||||
}
|
||||
@ -277,6 +302,10 @@ collect_neighbor_list_get(struct collect_neighbor_list *neighbors_list, int num)
|
||||
int i;
|
||||
struct collect_neighbor *n;
|
||||
|
||||
if(neighbors_list == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PRINTF("collect_neighbor_get %d\n", num);
|
||||
|
||||
i = 0;
|
||||
@ -294,6 +323,10 @@ collect_neighbor_list_get(struct collect_neighbor_list *neighbors_list, int num)
|
||||
void
|
||||
collect_neighbor_list_purge(struct collect_neighbor_list *neighbors_list)
|
||||
{
|
||||
if(neighbors_list == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
while(list_head(neighbors_list->list) != NULL) {
|
||||
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
|
||||
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);
|
||||
n->le_age = 0;
|
||||
n->age = 0;
|
||||
@ -322,6 +358,9 @@ collect_neighbor_tx_fail(struct collect_neighbor *n, uint16_t num_tx)
|
||||
void
|
||||
collect_neighbor_tx(struct collect_neighbor *n, uint16_t num_tx)
|
||||
{
|
||||
if(n == NULL) {
|
||||
return;
|
||||
}
|
||||
collect_link_estimate_update_tx(&n->le, num_tx);
|
||||
n->le_age = 0;
|
||||
n->age = 0;
|
||||
@ -330,6 +369,9 @@ collect_neighbor_tx(struct collect_neighbor *n, uint16_t num_tx)
|
||||
void
|
||||
collect_neighbor_rx(struct collect_neighbor *n)
|
||||
{
|
||||
if(n == NULL) {
|
||||
return;
|
||||
}
|
||||
collect_link_estimate_update_rx(&n->le);
|
||||
n->age = 0;
|
||||
}
|
||||
@ -337,6 +379,9 @@ collect_neighbor_rx(struct collect_neighbor *n)
|
||||
uint16_t
|
||||
collect_neighbor_link_estimate(struct collect_neighbor *n)
|
||||
{
|
||||
if(n == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if(collect_neighbor_is_congested(n)) {
|
||||
/* printf("Congested %d.%d, sould return %d, returning %d\n",
|
||||
n->addr.u8[0], n->addr.u8[1],
|
||||
@ -351,24 +396,38 @@ collect_neighbor_link_estimate(struct collect_neighbor *n)
|
||||
uint16_t
|
||||
collect_neighbor_rtmetric_link_estimate(struct collect_neighbor *n)
|
||||
{
|
||||
if(n == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return n->rtmetric + collect_link_estimate(&n->le);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
uint16_t
|
||||
collect_neighbor_rtmetric(struct collect_neighbor *n)
|
||||
{
|
||||
if(n == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return n->rtmetric;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
collect_neighbor_set_congested(struct collect_neighbor *n)
|
||||
{
|
||||
if(n == NULL) {
|
||||
return;
|
||||
}
|
||||
timer_set(&n->congested_timer, EXPECTED_CONGESTION_DURATION);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
collect_neighbor_is_congested(struct collect_neighbor *n)
|
||||
{
|
||||
if(n == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(timer_expired(&n->congested_timer)) {
|
||||
return 0;
|
||||
} else {
|
||||
|
@ -814,8 +814,10 @@ handle_ack(struct collect_conn *tc)
|
||||
chance that another parent will be chosen. */
|
||||
if(msg.flags & ACK_FLAGS_CONGESTED) {
|
||||
PRINTF("ACK flag indicated parent was congested.\n");
|
||||
collect_neighbor_set_congested(n);
|
||||
collect_neighbor_tx(n, tc->max_rexmits * 2);
|
||||
if(n != NULL) {
|
||||
collect_neighbor_set_congested(n);
|
||||
collect_neighbor_tx(n, tc->max_rexmits * 2);
|
||||
}
|
||||
update_rtmetric(tc);
|
||||
}
|
||||
if((msg.flags & ACK_FLAGS_DROPPED) == 0) {
|
||||
|
@ -72,7 +72,9 @@ recv_from_broadcast(struct broadcast_conn *broadcast, const rimeaddr_t *from)
|
||||
packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[0],
|
||||
packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[1]);
|
||||
if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &rimeaddr_node_addr)) {
|
||||
c->u->recv(c, from);
|
||||
if(c->u->recv) {
|
||||
c->u->recv(c, from);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
Loading…
Reference in New Issue
Block a user