From patchwork Tue Jun 16 12:53:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 484978 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 49B52140281 for ; Tue, 16 Jun 2015 22:54:40 +1000 (AEST) Received: from localhost ([::1]:40036 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4qNy-00031O-FK for incoming@patchwork.ozlabs.org; Tue, 16 Jun 2015 08:54:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50643) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4qNH-0001gX-Bg for qemu-devel@nongnu.org; Tue, 16 Jun 2015 08:54:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z4qNF-0007yR-MH for qemu-devel@nongnu.org; Tue, 16 Jun 2015 08:53:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43464) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4qNF-0007yN-9q for qemu-devel@nongnu.org; Tue, 16 Jun 2015 08:53:53 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id D71DDC99DA for ; Tue, 16 Jun 2015 12:53:52 +0000 (UTC) Received: from redhat.com (ovpn-116-59.ams2.redhat.com [10.36.116.59]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id t5GCroV0005214; Tue, 16 Jun 2015 08:53:51 -0400 Date: Tue, 16 Jun 2015 14:53:50 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1434458200-23440-2-git-send-email-mst@redhat.com> References: <1434458200-23440-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1434458200-23440-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, armbru@redhat.com, dgilbert@redhat.com Subject: [Qemu-devel] [PATCH RFC 1/3] error: don't rely on pointer comparisons 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 makes it possible to copy error_abort pointers, not just pass them on directly. Signed-off-by: Michael S. Tsirkin Reviewed-by: Eric Blake --- util/error.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/util/error.c b/util/error.c index 14f4351..ccf29ea 100644 --- a/util/error.c +++ b/util/error.c @@ -20,7 +20,13 @@ struct Error ErrorClass err_class; }; -Error *error_abort; +static Error error_abort_st = { .err_class = ERROR_CLASS_MAX }; +Error *error_abort = &error_abort_st; + +static bool error_is_abort(Error **errp) +{ + return errp && *errp && (*errp)->err_class == ERROR_CLASS_MAX; +} void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...) { @@ -40,7 +46,7 @@ void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...) va_end(ap); err->err_class = err_class; - if (errp == &error_abort) { + if (error_is_abort(errp)) { error_report_err(err); abort(); } @@ -76,7 +82,7 @@ void error_set_errno(Error **errp, int os_errno, ErrorClass err_class, va_end(ap); err->err_class = err_class; - if (errp == &error_abort) { + if (error_is_abort(errp)) { error_report_err(err); abort(); } @@ -121,7 +127,7 @@ void error_set_win32(Error **errp, int win32_err, ErrorClass err_class, va_end(ap); err->err_class = err_class; - if (errp == &error_abort) { + if (error_is_abort(errp)) { error_report_err(err); abort(); } @@ -168,7 +174,7 @@ void error_free(Error *err) void error_propagate(Error **dst_errp, Error *local_err) { - if (local_err && dst_errp == &error_abort) { + if (local_err && error_is_abort(dst_errp)) { error_report_err(local_err); abort(); } else if (dst_errp && !*dst_errp) {