Skip to contentSkip to conversation

gweb: Fix issue with const return value from memchr

PATCH Applied Rudi Heitbaum 1 participant 1 message Feb 12

lore
Share & tools
lore
#0 lore raw

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

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(-)
gweb/gweb.c +2 -2
index 4dbbb4c8..0a87da64 100644
@@ -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) {
Signature · 1 line
2.51.0