[PATCH v2 7/8] tests: Fix mode_t usage with va_arg()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Clang complains about it:

  virfilewrapper.c:270:27: error: second argument to 'va_arg'
    is of promotable type 'mode_t' (aka 'unsigned short'); this
    va_arg has undefined behavior because arguments will be
    promoted to 'int' [-Werror,-Wvarargs]

  mode = va_arg(ap, mode_t);
                    ^~~~~~

The issue was raised[1] when the patch was posted, but apparently
not acted upon. Implement the suggested fix.

[1] https://www.redhat.com/archives/libvir-list/2017-October/msg00127.html

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
 tests/virpcimock.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tests/virpcimock.c b/tests/virpcimock.c
index 001b320683..915327e91e 100644
--- a/tests/virpcimock.c
+++ b/tests/virpcimock.c
@@ -994,11 +994,11 @@ open(const char *path, int flags, ...)
 
     if (flags & O_CREAT) {
         va_list ap;
-        mode_t mode;
+        int mode;
         va_start(ap, flags);
-        mode = va_arg(ap, mode_t);
+        mode = va_arg(ap, int);
         va_end(ap);
-        ret = real_open(newpath ? newpath : path, flags, mode);
+        ret = real_open(newpath ? newpath : path, flags, (mode_t) mode);
     } else {
         ret = real_open(newpath ? newpath : path, flags);
     }
-- 
2.14.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux