[Libguestfs] [PATCH] daemon: Add an assertion to suppress a warning with GCC.

Richard W.M. Jones rjones at redhat.com
Wed Apr 19 16:47:29 UTC 2017


swap.c: In function 'do_mkswap_U':
swap.c:62:9: error: argument 1 null where non-null expected [-Werror=nonnull]
     if (strlen (label) > SWAP_LABEL_MAX) {
         ^~~~~~~~~~~~~~
---
 daemon/swap.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/daemon/swap.c b/daemon/swap.c
index 028bc1ee2..fea4a9dcf 100644
--- a/daemon/swap.c
+++ b/daemon/swap.c
@@ -22,6 +22,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <assert.h>
 
 #include "guestfs_protocol.h"
 #include "daemon.h"
@@ -58,6 +59,7 @@ do_mkswap (const char *device, const char *label, const char *uuid)
   ADD_ARG (argv, i, "-f");
 
   if (optargs_bitmask & GUESTFS_MKSWAP_LABEL_BITMASK) {
+    assert (label != NULL); /* suppress a warning with -O3 */
     if (strlen (label) > SWAP_LABEL_MAX) {
       reply_with_error ("%s: Linux swap labels are limited to %d bytes",
                         label, SWAP_LABEL_MAX);
-- 
2.12.0




More information about the Libguestfs mailing list