From patchwork Wed Dec 10 10:34:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 419578 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id DAEC31400D5 for ; Wed, 10 Dec 2014 22:07:31 +1100 (AEDT) Received: from localhost ([::1]:44733 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xyf7B-0004ci-6J for incoming@patchwork.ozlabs.org; Wed, 10 Dec 2014 06:07:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59537) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xyecc-00013u-Fr for qemu-devel@nongnu.org; Wed, 10 Dec 2014 05:36:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XyecX-0008SG-PR for qemu-devel@nongnu.org; Wed, 10 Dec 2014 05:35:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39644) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XyecX-0008S8-IP for qemu-devel@nongnu.org; Wed, 10 Dec 2014 05:35:49 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBAAZnHd007509 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 10 Dec 2014 05:35:49 -0500 Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sBAAYeSp016328; Wed, 10 Dec 2014 05:35:48 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Wed, 10 Dec 2014 11:34:36 +0100 Message-Id: <1418207679-32260-71-git-send-email-kwolf@redhat.com> In-Reply-To: <1418207679-32260-1-git-send-email-kwolf@redhat.com> References: <1418207679-32260-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com Subject: [Qemu-devel] [PULL 70/73] vmdk: Clean up descriptor file reading X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Fam Zheng Zeroing a buffer that will be filled right after is not necessary, and allocating a power of two + 1 is naughty. Suggested-by: Markus Armbruster Signed-off-by: Fam Zheng Reviewed-by: Don Koch Reviewed-by: Markus Armbruster Reviewed-by: Max Reitz Message-id: 1417649314-13704-4-git-send-email-famz@redhat.com Signed-off-by: Max Reitz Signed-off-by: Kevin Wolf --- block/vmdk.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 4ee0aed..5f43226 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -557,8 +557,8 @@ static char *vmdk_read_desc(BlockDriverState *file, uint64_t desc_offset, return NULL; } - size = MIN(size, 1 << 20); /* avoid unbounded allocation */ - buf = g_malloc0(size + 1); + size = MIN(size, (1 << 20) - 1); /* avoid unbounded allocation */ + buf = g_malloc(size + 1); ret = bdrv_pread(file, desc_offset, buf, size); if (ret < 0) { @@ -566,6 +566,7 @@ static char *vmdk_read_desc(BlockDriverState *file, uint64_t desc_offset, g_free(buf); return NULL; } + buf[ret] = 0; return buf; }