modem: hl7800: replace an snprintk with a strncpy

GCC format-truncation kicks in on this printk whenever the logging
configuration transforms the LOG_WRN below into a noop, and the snprintk
return argument become unused.

Fix that by switching to strncpy, fixes:

zephyrproject/zephyr/drivers/modem/hl7800.c:1786:74: warning: '%s'
directive output may be truncated writing up to 53 bytes into a region
of size 21 [-Wformat-truncation=]

reproduced with:

west build -p -b mg100 -T samples/net/telnet/sample.net.telnet

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
This commit is contained in:
Fabio Baltieri 2023-09-14 14:07:02 +00:00 committed by Fabio Baltieri
commit 196b1d6289

View file

@ -23,6 +23,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_MODEM_LOG_LEVEL);
#include <zephyr/pm/device.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/sys/util.h>
#include <zephyr/net/net_context.h>
#include <zephyr/net/net_if.h>
@ -1762,9 +1763,9 @@ done:
*/
static bool on_cmd_atcmdinfo_iccid(struct net_buf **buf, uint16_t len)
{
int ret;
char value[MDM_CCID_RESP_MAX_SIZE];
char *delim;
int iccid_len;
size_t out_len;
out_len = net_buf_linearize(value, sizeof(value), *buf, 0, len);
@ -1783,9 +1784,13 @@ static bool on_cmd_atcmdinfo_iccid(struct net_buf **buf, uint16_t len)
LOG_INF("EID: %s", delim + 1);
}
ret = snprintk(iface_ctx.mdm_iccid, sizeof(iface_ctx.mdm_iccid), "%s", value);
if (ret > MDM_HL7800_ICCID_MAX_STRLEN) {
LOG_WRN("ICCID too long: %d", ret);
iccid_len = strlen(value);
strncpy(iface_ctx.mdm_iccid, value, sizeof(iface_ctx.mdm_iccid));
len = MIN(iccid_len, sizeof(iface_ctx.mdm_iccid) - 1);
iface_ctx.mdm_iccid[len] = '\0';
if (iccid_len > len) {
LOG_WRN("ICCID too long: %d (max %d)", iccid_len, len);
}
LOG_INF("ICCID: %s", iface_ctx.mdm_iccid);