diff --git a/sys/include/net/gnrc/pkt.h b/sys/include/net/gnrc/pkt.h index e6756bbc4b..c170e60b6c 100644 --- a/sys/include/net/gnrc/pkt.h +++ b/sys/include/net/gnrc/pkt.h @@ -128,7 +128,7 @@ static inline size_t gnrc_pkt_len(gnrc_pktsnip_t *pkt) { size_t len = 0; - while (pkt) { + while (pkt != NULL) { len += pkt->size; pkt = pkt->next; } @@ -148,7 +148,7 @@ static inline size_t gnrc_pkt_len_upto(gnrc_pktsnip_t *pkt, gnrc_nettype_t type) { size_t len = 0; - while (pkt) { + while (pkt != NULL) { len += pkt->size; if (pkt->type == type) { @@ -172,7 +172,7 @@ static inline size_t gnrc_pkt_count(const gnrc_pktsnip_t *pkt) { size_t count = 0; - while (pkt) { + while (pkt != NULL) { ++count; pkt = pkt->next; } diff --git a/sys/net/gnrc/pkt/gnrc_pkt.c b/sys/net/gnrc/pkt/gnrc_pkt.c index 1a9c51d5de..e3f701a812 100644 --- a/sys/net/gnrc/pkt/gnrc_pkt.c +++ b/sys/net/gnrc/pkt/gnrc_pkt.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2016 Freie Universität Berlin + * 2017 HAW Hamburg * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -11,22 +12,18 @@ * * @file * @author Martine Lenders + * @author Sebastian Meiling */ -#include - #include "net/gnrc/pkt.h" -gnrc_pktsnip_t *gnrc_pktsnip_search_type(gnrc_pktsnip_t *ptr, +gnrc_pktsnip_t *gnrc_pktsnip_search_type(gnrc_pktsnip_t *pkt, gnrc_nettype_t type) { - while (ptr != NULL) { - if (ptr->type == type) { - return ptr; - } - ptr = ptr->next; + while ((pkt != NULL) && (pkt->type != type)) { + pkt = pkt->next; } - return NULL; + return pkt; } /** @} */