[Devel] [PATCH RHEL10 COMMIT] selftests/memfd: fix -Wmaybe-uninitialized warning in memfd_test
Konstantin Khorenko
khorenko at virtuozzo.com
Tue Mar 31 23:33:04 MSK 2026
The commit is pushed to "branch-rh10-6.12.0-55.52.1.5.x.vz10-ovz" and will appear at git at bitbucket.org:openvz/vzkernel.git
after rh10-6.12.0-55.52.1.5.12.vz10
------>
commit 4480ad84b54ff7d6bd4298a3b392b7ea7c7345de
Author: Konstantin Khorenko <khorenko at virtuozzo.com>
Date: Mon Mar 23 21:31:27 2026 +0100
selftests/memfd: fix -Wmaybe-uninitialized warning in memfd_test
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>
Reviewed-by: Vasileios Almpanis <vasileios.almpanis 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 95af2d78fd318..a6fb7128a5ac5 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