From patchwork Thu Aug 7 08:01:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 377783 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 F270A14009C for ; Thu, 7 Aug 2014 18:08:13 +1000 (EST) Received: from localhost ([::1]:44069 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFIk8-0008I8-2e for incoming@patchwork.ozlabs.org; Thu, 07 Aug 2014 04:08:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFIg3-00014o-7a for qemu-devel@nongnu.org; Thu, 07 Aug 2014 04:04:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XFIfu-0004yH-SE for qemu-devel@nongnu.org; Thu, 07 Aug 2014 04:03:59 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:5823) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFIfs-0004wy-Qz for qemu-devel@nongnu.org; Thu, 07 Aug 2014 04:03:50 -0400 Received: from 172.24.2.119 (EHLO szxeml448-hub.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BXR79023; Thu, 07 Aug 2014 16:02:44 +0800 (CST) Received: from localhost (10.177.22.69) by szxeml448-hub.china.huawei.com (10.82.67.191) with Microsoft SMTP Server id 14.3.158.1; Thu, 7 Aug 2014 16:02:37 +0800 From: zhanghailiang To: Date: Thu, 7 Aug 2014 16:01:50 +0800 Message-ID: <1407398512-20780-9-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 1.9.2.msysgit.0 In-Reply-To: <1407398512-20780-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1407398512-20780-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.22.69] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.65 Cc: kwolf@redhat.com, lkurusa@redhat.com, zhanghailiang , mst@redhat.com, jan.kiszka@siemens.com, riku.voipio@iki.fi, mjt@tls.msk.ru, peter.huangpeng@huawei.com, lcapitulino@redhat.com, stefanha@redhat.com, Li Liu , luonengjun@huawei.com, pbonzini@redhat.com, alex.bennee@linaro.org, rth@twiddle.net Subject: [Qemu-devel] [PATCH v3 08/10] qtest: check the value returned by fopen() 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 The function fopen() may fail, so check its return value. Signed-off-by: zhanghailiang Signed-off-by: Li Liu --- qtest.c | 5 +++++ tests/bios-tables-test.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/qtest.c b/qtest.c index 04a6dc1..ae9b636 100644 --- a/qtest.c +++ b/qtest.c @@ -536,6 +536,11 @@ void qtest_init(const char *qtest_chrdev, const char *qtest_log, Error **errp) if (qtest_log) { if (strcmp(qtest_log, "none") != 0) { qtest_log_fp = fopen(qtest_log, "w+"); + if (qtest_log_fp == NULL) { + error_setg(errp, "Failed to open log file for qtest: \"%s\"", + qtest_log); + return; + } } } else { qtest_log_fp = stderr; diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c index 045eb27..6a357c0 100644 --- a/tests/bios-tables-test.c +++ b/tests/bios-tables-test.c @@ -790,6 +790,8 @@ int main(int argc, char *argv[]) const char *arch = qtest_get_arch(); FILE *f = fopen(disk, "w"); int ret; + + g_assert(f != NULL); fwrite(boot_sector, 1, sizeof boot_sector, f); fclose(f);