1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys/net/gnrc_pktbuf: make use of memchk()

This commit is contained in:
Benjamin Valentin 2023-05-30 20:45:13 +02:00
parent 55dc66e942
commit 4476b2a024

View File

@ -30,6 +30,7 @@
#include "net/gnrc/pktbuf.h"
#include "net/gnrc/nettype.h"
#include "net/gnrc/pkt.h"
#include "string_utils.h"
#include "pktbuf_internal.h"
#include "pktbuf_static.h"
@ -61,18 +62,6 @@ static gnrc_pktsnip_t *_create_snip(gnrc_pktsnip_t *next, const void *data, size
gnrc_nettype_t type);
static void *_pktbuf_alloc(size_t size);
static const void *mem_is_set(const void *data, uint8_t c, size_t len)
{
const uint8_t *end = (uint8_t *)data + len;
for (const uint8_t *d = data; d != end; ++d) {
if (c != *d) {
return d;
}
}
return NULL;
}
static inline void _set_pktsnip(gnrc_pktsnip_t *pkt, gnrc_pktsnip_t *next,
void *data, size_t size, gnrc_nettype_t type)
{
@ -440,7 +429,7 @@ static void *_pktbuf_alloc(size_t size)
const void *mismatch;
if (CONFIG_GNRC_PKTBUF_CHECK_USE_AFTER_FREE &&
(mismatch = mem_is_set(ptr + 1, CANARY, size - sizeof(_unused_t)))) {
(mismatch = memchk(ptr + 1, CANARY, size - sizeof(_unused_t)))) {
printf("[%p] mismatch at offset %"PRIuPTR"/%u (ignoring %u initial bytes that were repurposed)\n",
(void *)ptr, (uintptr_t)mismatch - (uintptr_t)ptr, (unsigned)size, (unsigned)sizeof(_unused_t));
#ifdef MODULE_OD