From 8ca36cdf05e3ca0546b86ca25910752ded9d1d79 Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Tue, 15 Aug 2023 12:52:25 +0200 Subject: [PATCH] coap_session.c: Fix GCC array bounds warning for memcpy Copying from the multidimensional coap_layers_coap array into the coap_layers of endpoint::sock.lfunc triggers a warning from GCC v13.2.0 as the global variable has no space for the end marker COAP_PROTO_LAST. This change adds an assertion to indicate that proto is always less than COAP_PROTO_LAST. --- src/coap_session.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coap_session.c b/src/coap_session.c index 69bd90fe..5cc3073d 100644 --- a/src/coap_session.c +++ b/src/coap_session.c @@ -1756,6 +1756,7 @@ coap_new_endpoint(coap_context_t *context, const coap_address_t *listen_addr, co ep->context = context; ep->proto = proto; ep->sock.endpoint = ep; + assert(proto < COAP_PROTO_LAST); memcpy(&ep->sock.lfunc, coap_layers_coap[proto], sizeof(ep->sock.lfunc)); if (COAP_PROTO_NOT_RELIABLE(proto)) {