From: Zhou Yuhang <zhouyuh...@kylinos.cn>

Flock fl and fl2 are not initialized after definition.
Due to struct padding, this may cause memcmp() to return
a non-zero value. The output is as follows:

 # [INFO] opened fds 3 4
 # [SUCCESS] set OFD read lock on first fd
 # [SUCCESS] read and write locks conflicted
 # [SUCCESS] F_UNLCK test returns: locked, type 0 pid -1 len 3
 # [FAIL] F_UNLCK test returns: locked, type 0 pid -1 len 3

Initialize them to zero to solve this problem.

Signed-off-by: Zhou Yuhang <zhouyuh...@kylinos.cn>
---
 tools/testing/selftests/filelock/ofdlocks.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/testing/selftests/filelock/ofdlocks.c 
b/tools/testing/selftests/filelock/ofdlocks.c
index a55b79810ab2..84e25505bebb 100644
--- a/tools/testing/selftests/filelock/ofdlocks.c
+++ b/tools/testing/selftests/filelock/ofdlocks.c
@@ -36,6 +36,8 @@ int main(void)
 {
        int rc;
        struct flock fl, fl2;
+       memset(&fl, 0, sizeof(fl));
+       memset(&fl2, 0, sizeof(fl2));
        int fd = open("/tmp/aa", O_RDWR | O_CREAT | O_EXCL, 0600);
        int fd2 = open("/tmp/aa", O_RDONLY);
 
-- 
2.33.0


Reply via email to