From cf5f1a09e994b4b2560151d28be156ebb3f5a07b Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Tue, 12 Mar 2019 22:16:49 +0100 Subject: [PATCH] coap_session.c: minimize buffer space for coap_session_str() The buffer szSession for storing a textual representation of the session structure has been trimmed down to 2 * (INET6_ADDRSTRLEN + 8) + 24, allowing two IPv6 address references, port numbers, some structuring text and about eight characters for the interface index. Background: coap_print_addr() calls inet_ntop() for address output which on RIOT is mapped to ipv6_addr_to_str(). As the length parameter of ipv6_addr_to_str() is a uint8_t, only the lower eight bits of szSession's size are effectively used. The previous value of 256 then always lead no ENOSPC because 256 & 0xff == 0. --- src/coap_session.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coap_session.c b/src/coap_session.c index 1d05d625..6556b512 100644 --- a/src/coap_session.c +++ b/src/coap_session.c @@ -1187,7 +1187,7 @@ coap_session_get_by_peer(coap_context_t *ctx, } const char *coap_session_str(const coap_session_t *session) { - static char szSession[256]; + static char szSession[2 * (INET6_ADDRSTRLEN + 8) + 24]; char *p = szSession, *end = szSession + sizeof(szSession); if (coap_print_addr(&session->addr_info.local, (unsigned char*)p, end - p) > 0)