[PATCH 6/8] gweb: Do not append NULL body to send buffer

Jussi Laakkonen <[email protected]> Thu, 10 Apr 2025 18:58:44 +0300
Newsgroups dev.linux.lists.connman
Message-ID <[email protected]>
Fix Clang analyzer warning about writing uninitialized content to the
buffer.
---
 gweb/gweb.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gweb/gweb.c b/gweb/gweb.c
index c17475c5..4dbbb4c8 100644
--- a/gweb/gweb.c
+++ b/gweb/gweb.c
@@ -920,8 +920,8 @@ static void start_request(struct web_session *session)
 {
 	GString *buf = session->send_buffer;
 	const char *version;
-	const guint8 *body;
-	gsize length;
+	const guint8 *body = NULL;
+	gsize length = 0;

 	debug(session->web, "request %s from %s",
 					session->request, session->host);
@@ -981,7 +981,7 @@ static void start_request(struct web_session *session)
 			g_string_append_printf(buf, "%zx\r\n", length);
 			g_string_append_len(buf, (char *) body, length);
 			g_string_append(buf, "\r\n");
-		} else if (session->fd == -1)
+		} else if (session->fd == -1 && body)
 			g_string_append_len(buf, (char *) body, length);
 	}
 }
--
2.39.5