[PATCH v3 6/9] tests: Fix mode_t usage with va_arg()

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

 



Clang complains about it:

  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);
                      ^~~~~~

Work around the issue by passing int to va_arg() and casting
its return value to mode_t afterwards.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
 tests/nssmock.c       | 2 +-
 tests/vircgroupmock.c | 2 +-
 tests/virpcimock.c    | 2 +-
 tests/virtestmock.c   | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tests/nssmock.c b/tests/nssmock.c
index 7929c3061c..fc8e6b22f0 100644
--- a/tests/nssmock.c
+++ b/tests/nssmock.c
@@ -87,7 +87,7 @@ open(const char *path, int flags, ...)
         va_list ap;
         mode_t mode;
         va_start(ap, flags);
-        mode = va_arg(ap, int);
+        mode = (mode_t) va_arg(ap, int);
         va_end(ap);
         ret = real_open(newpath ? newpath : path, flags, mode);
     } else {
diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c
index 56337c2f3e..51861be38e 100644
--- a/tests/vircgroupmock.c
+++ b/tests/vircgroupmock.c
@@ -731,7 +731,7 @@ int open(const char *path, int flags, ...)
         va_list ap;
         mode_t mode;
         va_start(ap, flags);
-        mode = va_arg(ap, mode_t);
+        mode = (mode_t) va_arg(ap, int);
         va_end(ap);
         ret = real_open(newpath ? newpath : path, flags, mode);
     } else {
diff --git a/tests/virpcimock.c b/tests/virpcimock.c
index 79352175de..7e4ac191d0 100644
--- a/tests/virpcimock.c
+++ b/tests/virpcimock.c
@@ -983,7 +983,7 @@ open(const char *path, int flags, ...)
         va_list ap;
         mode_t mode;
         va_start(ap, flags);
-        mode = va_arg(ap, mode_t);
+        mode = (mode_t) va_arg(ap, int);
         va_end(ap);
         ret = real_open(newpath ? newpath : path, flags, mode);
     } else {
diff --git a/tests/virtestmock.c b/tests/virtestmock.c
index 4e679f35c0..c3b0aa2d9c 100644
--- a/tests/virtestmock.c
+++ b/tests/virtestmock.c
@@ -181,7 +181,7 @@ int open(const char *path, int flags, ...)
         va_list ap;
         mode_t mode;
         va_start(ap, flags);
-        mode = va_arg(ap, mode_t);
+        mode = (mode_t) va_arg(ap, int);
         va_end(ap);
         ret = real_open(path, flags, mode);
     } else {
-- 
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