[PATCH 3/5] gweb: Fix issue with const return value from memchr

Rudi Heitbaum <[email protected]> Thu, 12 Feb 2026 13:26:54 +0000
Newsgroups dev.linux.lists.connman
Message-ID <aY3VHuDI-6Ir3Xt-@01676446e9f4>
When compiling with recent gcc and glibc-2.43 the --Wdiscarded-qualifiers
warning occurs because with ISO C23, the function memchr that return
pointers into their input arrays now have definitions as macros that
return a pointer to a const-qualified type when the input argument is
a pointer to a const-qualified type.

../gweb/gweb.c: In function 'decode_chunked':
../gweb/gweb.c:1034:29: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
 1034 |                         pos = memchr(ptr, '\n', len);
      |                             ^
../gweb/gweb.c: In function 'g_web_parser_feed_data':                                                                              ../gweb/gweb.c:2922:29: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]            2922 |                         pos = memchr(ptr, chr, length);                                                                          |                             ^
---
 gweb/gweb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gweb/gweb.c b/gweb/gweb.c
index 4dbbb4c8..0a87da64 100644
--- a/gweb/gweb.c
+++ b/gweb/gweb.c
@@ -1025,7 +1025,7 @@ static int decode_chunked(struct web_session *session,
 	gsize counter;
 
 	while (len > 0) {
-		guint8 *pos;
+		const guint8 *pos;
 		gsize count;
 		char *str;
 
@@ -2917,7 +2917,7 @@ void g_web_parser_feed_data(GWebParser *parser,
 		guint8 chr = parser->token_str[parser->token_pos];
 
 		if (parser->token_pos == 0) {
-			guint8 *pos;
+			const guint8 *pos;
 
 			pos = memchr(ptr, chr, length);
 			if (!pos) {
-- 
2.51.0