Hi Amit, Thanks for the follow-up and for working on a more complete solution.
Your approach using g_getenv() and g_strstr_len() makes sense regarding consistency with GLib/QEMU conventions and avoiding future issues with stricter compilers. I appreciate the note and the rebase on top of my merged commit! Regards, Matthew On Friday, 22 May 2026 at 09:27, Amit Machhiwal <[email protected]> wrote: > Hi Matthew, > > Thank you for addressing the const qualifier warning in qtest_verbose(). Your > fix correctly resolves the immediate compilation issue with modern compilers. > > I had independently worked on this same issue and submitted a similar fix as > part of a patch series: > > https://lore.kernel.org/all/[email protected]/ > > While both our approaches fix the immediate strstr() warning by making 'found' > const, I noticed that getenv() still returns char * despite environment > strings > being semantically read-only. This creates a subtle const-correctness gap that > stricter compilers (like GCC 16) may flag in the future. > > I've prepared an improved v2 patch [2] that builds upon your merged fix by > using > g_getenv() and g_strstr_len() to maintain const correctness throughout. This > approach: > > - Uses g_getenv() which returns const gchar *, matching the read-only > semantics > of environment variables > - Employs g_strstr_len() for consistent use of GLib string functions, aligning > with QEMU conventions > - Eliminates all const-correctness warnings with strict compilers The v2 patch > supersedes my earlier attempt and is rebased on top of your merged commit > (e68da5b7a2cd). > > Thanks again for the quick fix! > > [1] https://lore.kernel.org/all/[email protected]/ > [2] https://lore.kernel.org/all/[email protected]/ > > Regards, > Amit > > On 2026/05/18 12:53 PM, Fabiano Rosas wrote: > > From: Matthew Penney <[email protected]> > > > > Modern compilers warn that the result of strstr() may discard > > const qualifiers when assigned to a non-const pointer. > > > > Make 'found' a const char * to fix the warning. > > > > Signed-off-by: Matthew Penney <[email protected]> > > Reviewed-by: Thomas Huth <[email protected]> > > Tested-by: Thomas Huth <[email protected]> > > Reviewed-by: Marc-André Lureau <[email protected]> > > Tested-by: Philippe Mathieu-Daudé <[email protected]> > > Reviewed-by: Philippe Mathieu-Daudé <[email protected]> > > Reviewed-by: Pierrick Bouvier <[email protected]> > > Signed-off-by: Fabiano Rosas <[email protected]> > > --- > > 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 bf9284b9a1..b1e06ea364 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.51.0 > > > > >
