Skip to contentSkip to conversation

tests/qtest: Fix const qualifier build errors

PATCH In review Cédric Le Goater 3 participants 3 messages May 15

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/qtest: Fix const qualifier build errors

A recent change in glibc 2.42.9000 [1] changes the return type of strstr() and other string functions to be 'const char *' when the input is a 'const char *'. This breaks the build in :

../tests/qtest/libqtest.c: In function ‘qtest_verbose’:
../tests/qtest/libqtest.c:2175:15: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
2175 | found = strstr(log, domain);

Fix this by changing the type of the variable that store the result to 'const char *'.

[1] https://sourceware.org/git/?p=glibc.git;a=commit;h=cd748a63ab1a7ae846175c532a3daab341c62690

Fixes f606321be88c ("tests/qtest: Individual verbose switches")
---
 tests/qtest/libqtest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/libqtest.c +1 -1
index bf9284b9a131..b1e06ea364ec 100644
@@ -2146,7 +2146,7 @@ bool mkimg(const char *file, const char *fmt, unsigned size_mb)
 bool qtest_verbose(const char *domain)
 {
     const char *log = getenv("QTEST_LOG");
-    char *found;
+    const char *found;
 
     assert(domain);
 
Signature · 1 line
2.54.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Cédric Le Goater

A recent change in glibc 2.42.9000 [1] changes the return type of strstr() and other string functions to be 'const char *' when the input is a 'const char *'. This breaks the build in :

../tests/qtest/libqtest.c: In function ‘qtest_verbose’:
../tests/qtest/libqtest.c:2175:15: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
2175 | found = strstr(log, domain);

Fix this by changing the type of the variable that store the result to 'const char *'.

Quoted 8 lines

[1] https://sourceware.org/git/?p=glibc.git;a=commit;h=cd748a63ab1a7ae846175c532a3daab341c62690

Fixes f606321be88c ("tests/qtest: Individual verbose switches")
---
 tests/qtest/libqtest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#2 lore raw
In reply to Cédric Le Goater
Quoted 25 lines · Cédric Le Goater

A recent change in glibc 2.42.9000 [1] changes the return type of strstr() and other string functions to be 'const char *' when the input is a 'const char *'. This breaks the build in :

../tests/qtest/libqtest.c: In function ‘qtest_verbose’:
../tests/qtest/libqtest.c:2175:15: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
2175 | found = strstr(log, domain);

Fix this by changing the type of the variable that store the result to 'const char *'.

[1] https://sourceware.org/git/?p=glibc.git;a=commit;h=cd748a63ab1a7ae846175c532a3daab341c62690

Fixes f606321be88c ("tests/qtest: Individual verbose switches")
---
 tests/qtest/libqtest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/libqtest.c +0 -0
index bf9284b9a131..b1e06ea364ec 100644

tests/qtest/libqtest.c bool mkimg(const char *file, const char *fmt, unsigned size_mb) · line 2151

Quoted 7 lines
tests/qtest/libqtest.c +1 -1
@@ -2146,7 +2146,7 @@ bool mkimg(const char *file, const char *fmt, unsigned size_mb)
 bool qtest_verbose(const char *domain)
 {
     const char *log = getenv("QTEST_LOG");
-    char *found;
+    const char *found;
 
     assert(domain);

Same fix posted slightly earlier:

https://lore.kernel.org/qemu-devel/[email protected]/

thanks
-- PMM