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

[libvirt] [PATCH] storage_backend.c: assure clang that inputvol can't be NULL



clang was complaining that a NULL inputvol would be dereferenced
in that "could not open..." diagnostic.

Since the two sole callers of this function are careful
to call it only when inputvol is non-NULL, this is a good
case for giving the parameter the nonnull attribute:


>From 314278acb021a1f2e63494fab352bd6e9a4a38bb Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering redhat com>
Date: Thu, 3 Sep 2009 10:22:57 +0200
Subject: [PATCH] storage_backend.c: assure clang that inputvol can't be NULL

* src/storage_backend.c (virStorageBackendCopyToFD): Declare inputvol
parameter to be "nonnull".
Remove test for non-NULL inputvol.  Both callers ensure it's non-NULL.
---
 src/storage_backend.c |   16 +++++++---------
 1 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/storage_backend.c b/src/storage_backend.c
index c818142..8d1187e 100644
--- a/src/storage_backend.c
+++ b/src/storage_backend.c
@@ -1,7 +1,7 @@
 /*
  * storage_backend.c: internal storage driver backend contract
  *
- * Copyright (C) 2007-2008 Red Hat, Inc.
+ * Copyright (C) 2007-2009 Red Hat, Inc.
  * Copyright (C) 2007-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -106,7 +106,7 @@ enum {
 static int
 virStorageBackendCopyToFD(virConnectPtr conn,
                           virStorageVolDefPtr vol,
-                          virStorageVolDefPtr inputvol,
+                          virStorageVolDefPtr inputvol ATTRIBUTE_NONNULL,
                           int fd,
                           unsigned long long *total,
                           int is_dest_file)
@@ -119,13 +119,11 @@ virStorageBackendCopyToFD(virConnectPtr conn,
     char zerobuf[512];
     char *buf = NULL;

-    if (inputvol) {
-        if ((inputfd = open(inputvol->target.path, O_RDONLY)) < 0) {
-            virReportSystemError(conn, errno,
-                                 _("could not open input path '%s'"),
-                                 inputvol->target.path);
-            goto cleanup;
-        }
+    if ((inputfd = open(inputvol->target.path, O_RDONLY)) < 0) {
+        virReportSystemError(conn, errno,
+                             _("could not open input path '%s'"),
+                             inputvol->target.path);
+        goto cleanup;
     }

     bzero(&zerobuf, sizeof(zerobuf));
--
1.6.4.2.395.ge3d52


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