[Devel] [PATCH vz10 08/15] selftests/memfd: fix -Wmaybe-uninitialized warning in memfd_test

Vasileios Almpanis vasileios.almpanis at virtuozzo.com
Mon Mar 30 11:26:04 MSK 2026


Reviewed-by: Vasileios Almpanis <vasileios.almpanis at virtuozzo.com>

On 3/23/26 9:31 PM, Konstantin Khorenko wrote:
>    memfd_test.c: In function 'mfd_fail_grow_write.part.0':
>    memfd_test.c:685:13: warning: '<unknown>' may be used uninitialized [-Wmaybe-uninitialized]
>      685 |         l = pwrite(fd, buf, mfd_def_size * 8, 0);
>          |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> pwrite() is declared with attribute 'access (read_only, 2, 3)', so GCC
> knows it reads from the buffer. malloc() returns uninitialized memory,
> hence the warning. Use calloc() to zero-initialize the buffer. The
> actual contents don't matter here since the test verifies that pwrite()
> fails on a sealed memfd.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-127529
> Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
>
> Feature: fix selftests
> Made-with: Cursor
> ---
>   tools/testing/selftests/memfd/memfd_test.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c
> index 95af2d78fd31..a6fb7128a5ac 100644
> --- a/tools/testing/selftests/memfd/memfd_test.c
> +++ b/tools/testing/selftests/memfd/memfd_test.c
> @@ -676,7 +676,7 @@ static void mfd_fail_grow_write(int fd)
>   	if (hugetlbfs_test)
>   		return;
>   
> -	buf = malloc(mfd_def_size * 8);
> +	buf = calloc(1, mfd_def_size * 8);
>   	if (!buf) {
>   		printf("malloc(%zu) failed: %m\n", mfd_def_size * 8);
>   		abort();


More information about the Devel mailing list