GCC 16 tightens const-correctness checking and reports:
error: assignment discards 'const' qualifier from pointer target type
[-Werror=discarded-qualifiers]
found = strstr(log, domain);
^
in qtest_verbose() because strstr() returns a non-const pointer while
operating on a const-qualified string from getenv().
While getenv() returns char *, the returned environment string is
semantically treated as read-only. Use g_getenv() and g_strstr_len() so
that the local string pointers remain const-qualified throughout. This
maintains const correctness throughout and aligns with QEMU's use of
GLib string functions.
No functional change intended.
Signed-off-by: Amit Machhiwal <[email protected]>
---
tests/qtest/libqtest.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index bf9284b9a131..cb80ab23182a 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -2145,8 +2145,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 gchar *found, *log = g_getenv("QTEST_LOG");
assert(domain);
@@ -2172,11 +2171,11 @@ bool qtest_verbose(const char *domain)
* QTEST_LOG=<domain1>,-<domain2> (only false for domain2)
* allows other separators, except - and +
*/
- found = strstr(log, domain);
+ found = g_strstr_len(log, -1, domain);
if (found) {
/* reject options given twice */
- assert(!strstr(found + strlen(domain), domain));
+ assert(!g_strstr_len(found + strlen(domain), -1, domain));
if (found > log) {
ptrdiff_t i = found - log - 1;
@@ -2190,7 +2189,7 @@ bool qtest_verbose(const char *domain)
* If filtering out a specific domain, all others are
* enabled.
*/
- return !!strstr(log, "-");
+ return !!g_strstr_len(log, -1, "-");
}
}
--
2.50.1 (Apple Git-155)