Re: [PATCH 2/3] selftests/nolibc: cast execve() argv string to character pointer

From: David Laight

Date: Thu May 21 2026 - 14:21:54 EST


On Thu, 21 May 2026 18:29:30 +0200
Thomas Weißschuh <linux@xxxxxxxxxxxxxx> wrote:

> The existing code would trigger a warning under -Wwrite-strings which is
> about to be enabled. execve() is specified as not modifying the argv
> array, but the exact semantics are not representable in the type system.

I suspect you'll have to fix it again to avoid 'casting away const'.
Can you use something like (char[]){"/"} ?

-- David

> See the section "Rationale" in page linked below.
>
> Link: https://pubs.opengroup.org/onlinepubs/9799919799/functions/exec.html
> Signed-off-by: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
> ---
> tools/testing/selftests/nolibc/nolibc-test.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> index c3867cc570c6..9f8cb3672737 100644
> --- a/tools/testing/selftests/nolibc/nolibc-test.c
> +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> @@ -1533,7 +1533,7 @@ int run_syscall(int min, int max)
> CASE_TEST(dup2_m1); tmp = dup2(-1, 100); EXPECT_SYSER(1, tmp, -1, EBADF); if (tmp != -1) close(tmp); break;
> CASE_TEST(dup3_0); tmp = dup3(0, 100, 0); EXPECT_SYSNE(1, tmp, -1); close(tmp); break;
> CASE_TEST(dup3_m1); tmp = dup3(-1, 100, 0); EXPECT_SYSER(1, tmp, -1, EBADF); if (tmp != -1) close(tmp); break;
> - CASE_TEST(execve_root); EXPECT_SYSER(1, execve("/", (char*[]){ [0] = "/", [1] = NULL }, NULL), -1, EACCES); break;
> + CASE_TEST(execve_root); EXPECT_SYSER(1, execve("/", (char*[]){ [0] = (char *)"/", [1] = NULL }, NULL), -1, EACCES); break;
> CASE_TEST(fchdir_stdin); EXPECT_SYSER(1, fchdir(STDIN_FILENO), -1, ENOTDIR); break;
> CASE_TEST(fchdir_badfd); EXPECT_SYSER(1, fchdir(-1), -1, EBADF); break;
> CASE_TEST(file_stream); EXPECT_SYSZR(1, test_file_stream()); break;
>