Patchwork [04/10] qed: don't pass NULL to memcpy

login
register
mail settings
Submitter Stefan Hajnoczi
Date Oct. 26, 2011, 2:22 p.m.
Message ID <1319638933-19063-5-git-send-email-stefanha@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/121913/
State New
Headers show

Comments

Stefan Hajnoczi - Oct. 26, 2011, 2:22 p.m.
From: Pavel Borzenkov <pavel.borzenkov@gmail.com>

Spotted by Clang Analyzer

[Note this memcpy call has always been safe because the length will be 0
when the pointer is NULL]

Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 block/qed.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

Patch

diff --git a/block/qed.c b/block/qed.c
index e87dc4d..7fab155 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -1425,8 +1425,10 @@  static int bdrv_qed_change_backing_file(BlockDriverState *bs,
     memcpy(buffer, &le_header, sizeof(le_header));
     buffer_len = sizeof(le_header);
 
-    memcpy(buffer + buffer_len, backing_file, backing_file_len);
-    buffer_len += backing_file_len;
+    if (backing_file) {
+        memcpy(buffer + buffer_len, backing_file, backing_file_len);
+        buffer_len += backing_file_len;
+    }
 
     /* Write new header */
     ret = bdrv_pwrite_sync(bs->file, 0, buffer, buffer_len);