From patchwork Wed Jun 26 09:15:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hu Tao X-Patchwork-Id: 254650 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4085F2C0095 for ; Wed, 26 Jun 2013 19:24:47 +1000 (EST) Received: from localhost ([::1]:33429 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Urly1-0004Hx-2F for incoming@patchwork.ozlabs.org; Wed, 26 Jun 2013 05:24:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43977) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Urlpe-00073t-3t for qemu-devel@nongnu.org; Wed, 26 Jun 2013 05:16:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Urlpa-0003RF-Uk for qemu-devel@nongnu.org; Wed, 26 Jun 2013 05:16:06 -0400 Received: from [222.73.24.84] (port=26102 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Urlpa-0003Pj-L8 for qemu-devel@nongnu.org; Wed, 26 Jun 2013 05:16:02 -0400 X-IronPort-AV: E=Sophos;i="4.87,943,1363104000"; d="scan'208";a="7688776" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 26 Jun 2013 17:13:04 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r5Q9FxSf020491; Wed, 26 Jun 2013 17:15:59 +0800 Received: from G08FNSTD100614.fnst.cn.fujitsu.com ([10.167.233.156]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013062617144331-2496227 ; Wed, 26 Jun 2013 17:14:43 +0800 From: Hu Tao To: qemu-devel@nongnu.org, seabios@seabios.org Date: Wed, 26 Jun 2013 17:15:02 +0800 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/06/26 17:14:43, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/06/26 17:14:43, Serialize complete at 2013/06/26 17:14:43 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 222.73.24.84 Cc: Vasilis Liaskovitis Subject: [Qemu-devel] [PATCH v5 4/7] set psize to 0 when romfile_loadfile failed 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 Signed-off-by: Hu Tao --- src/romfile.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/romfile.c b/src/romfile.c index ea71d1f..b1b89bb 100644 --- a/src/romfile.c +++ b/src/romfile.c @@ -51,28 +51,33 @@ romfile_loadfile(const char *name, int *psize) { struct romfile_s *file = romfile_find(name); if (!file) - return NULL; + goto failed; int filesize = file->size; if (!filesize) - return NULL; + goto failed; char *data = malloc_tmphigh(filesize+1); if (!data) { warn_noalloc(); - return NULL; + goto failed; } dprintf(5, "Copying romfile '%s' (len %d)\n", name, filesize); int ret = file->copy(file, data, filesize); if (ret < 0) { free(data); - return NULL; + goto failed; } if (psize) *psize = filesize; data[filesize] = '\0'; return data; + +failed: + if (psize) + *psize = 0; + return NULL; } // Attempt to load an integer from the given file - return 'defval'