From f0258dbe4d71b5e5bf4565878cd8cce9a6dac0b3 Mon Sep 17 00:00:00 2001 From: Veijo Pesonen Date: Thu, 19 Jan 2023 09:46:25 +0200 Subject: [PATCH] net: lwm2m: Sufficient memory for resource names Full resource names aren't as long as combined basename- and name-buffer sizes but the compiler doesn't know it. Increasing the buffer size to avoid the compiler warning. Signed-off-by: Veijo Pesonen --- subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c b/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c index 80b74bbb213..88a48d0336c 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c +++ b/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c @@ -713,7 +713,10 @@ static int do_write_op_item(struct lwm2m_message *msg, struct record *rec) /* Composite op - name with basename */ char name[SENML_MAX_NAME_SIZE] = { 0 }; /* Null terminated name */ int len = 0; - char fqn[MAX_RESOURCE_LEN + 1] = {0}; + /* Compiler requires reserving space for full length basename and name even though those two + * combined do not exceed MAX_RESOURCE_LEN + */ + char fqn[MAX_RESOURCE_LEN + SENML_MAX_NAME_SIZE + 1] = {0}; fd = engine_get_in_user_data(&msg->in); if (!fd) { @@ -819,7 +822,10 @@ static uint8_t parse_composite_read_paths(struct lwm2m_message *msg, { char basename[MAX_RESOURCE_LEN + 1] = {0}; /* to include terminating null */ char name[MAX_RESOURCE_LEN + 1] = {0}; /* to include terminating null */ - char fqn[MAX_RESOURCE_LEN + 1] = {0}; + /* Compiler requires reserving space for full length basename and name even though those two + * combined do not exceed MAX_RESOURCE_LEN + */ + char fqn[2 * MAX_RESOURCE_LEN + 1] = {0}; struct lwm2m_obj_path path; struct cbor_in_fmt_data *fd; uint8_t paths = 0;