[PATCH] tests/qtest: Fix const qualifier build errors

Cédric Le Goater posted 1 patch 2 weeks, 1 day ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260515170658.187252-1-clg@redhat.com
Maintainers: Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
tests/qtest/libqtest.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] tests/qtest: Fix const qualifier build errors
Posted by Cédric Le Goater 2 weeks, 1 day ago
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")
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 tests/qtest/libqtest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index bf9284b9a131..b1e06ea364ec 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -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);
 
-- 
2.54.0


Re: [PATCH] tests/qtest: Fix const qualifier build errors
Posted by Peter Maydell 2 weeks ago
On Fri, 15 May 2026 at 18:07, Cédric Le Goater <clg@redhat.com> wrote:
>
> 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")
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
>  tests/qtest/libqtest.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index bf9284b9a131..b1e06ea364ec 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -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/20260514191844.105888-1-matt@matthewpenney.net/

thanks
-- PMM
Re: [PATCH] tests/qtest: Fix const qualifier build errors
Posted by Pierrick Bouvier 2 weeks, 1 day ago
On 5/15/2026 10:06 AM, Cédric Le Goater wrote:
> 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")
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
>  tests/qtest/libqtest.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>