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.
This commit is contained in:
Olaf Bergmann authored and obgm committed 2023-08-15 13:15:22 +02:00
1 parent c8a305a6cd
commit 8ca36cdf05
1 file changed
+1
+1
View File
@@ -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)) {