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

Andrea Bolognani abologna at redhat.com
Mon Apr 30 16:53:02 UTC 2018


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 at redhat.com>
---
 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




More information about the libvir-list mailing list