Skip to content

Commit

Permalink
net: ip: Fix dereference before NULL check
Browse files Browse the repository at this point in the history
Fix warnings like "Dereference before NULL check". Also make check
readable.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
  • Loading branch information
finikorg authored and fabiobaltieri committed Dec 30, 2022
1 parent d4c7f04 commit d320100
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions subsys/net/ip/net_pkt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1775,15 +1775,17 @@ int net_pkt_copy(struct net_pkt *pkt_dst,

static int32_t net_pkt_find_offset(struct net_pkt *pkt, uint8_t *ptr)
{
struct net_buf *buf = pkt->buffer;
struct net_buf *buf;
uint32_t ret = -EINVAL;
uint16_t offset;

if (!(ptr && pkt && buf)) {
if (!ptr || !pkt || !pkt->buffer) {
return ret;
}

offset = 0U;
buf = pkt->buffer;

while (buf) {
if (buf->data <= ptr && ptr <= (buf->data + buf->len)) {
ret = offset + (ptr - buf->data);
Expand Down

0 comments on commit d320100

Please sign in to comment.