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

Andrea Bolognani posted 9 patches 7 years ago
[libvirt] [PATCH v3 6/9] tests: Fix mode_t usage with va_arg()
Posted by Andrea Bolognani 7 years ago
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@redhat.com>
---
 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@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v3 6/9] tests: Fix mode_t usage with va_arg()
Posted by Daniel P. Berrangé 7 years ago
On Thu, May 03, 2018 at 12:54:20PM +0200, Andrea Bolognani wrote:
> 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@redhat.com>
> ---
>  tests/nssmock.c       | 2 +-
>  tests/vircgroupmock.c | 2 +-
>  tests/virpcimock.c    | 2 +-
>  tests/virtestmock.c   | 2 +-
>  4 files changed, 4 insertions(+), 4 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

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