From 6f913894964b2df39ed426bf56ec94376a406597 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Date: Tue, 28 Sep 2021 23:25:19 +0200 Subject: [PATCH] at_send_command: improve logging when snprintf(3) fails --- src/at.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/at.c b/src/at.c index 399913c..2527bca 100644 --- a/src/at.c +++ b/src/at.c @@ -68,8 +68,14 @@ gboolean at_send_command(struct EG25Manager *manager) else if (at_cmd->subcmd && at_cmd->value) len = snprintf(command, sizeof(command), "AT+%s=\"%s\",%s\r\n", at_cmd->cmd, at_cmd->subcmd, at_cmd->value); - if (len < 0 || len >= sizeof(command)) { - g_warning("AT command does not fit into buffer\n"); + if (len < 0) { + g_warning("snprintf(3) failed"); + at_next_command(manager); + return FALSE; + } + else if (len >= sizeof(command)) { + g_warning("AT command does not fit into buffer " + "(%d bytes required, %zu available)", len, sizeof(command)); at_next_command(manager); return FALSE; }