From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z57iN-0000wm-0Q for qemu-devel@nongnu.org; Wed, 17 Jun 2015 03:24:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z57iJ-0001g2-1v for qemu-devel@nongnu.org; Wed, 17 Jun 2015 03:24:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42324) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z57iI-0001fm-TT for qemu-devel@nongnu.org; Wed, 17 Jun 2015 03:24:47 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 85CE736B4C3 for ; Wed, 17 Jun 2015 07:24:46 +0000 (UTC) Date: Wed, 17 Jun 2015 09:24:43 +0200 From: "Michael S. Tsirkin" Message-ID: <1434525861-21768-2-git-send-email-mst@redhat.com> References: <1434525861-21768-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1434525861-21768-1-git-send-email-mst@redhat.com> Subject: [Qemu-devel] [PATCH v2 1/3] error: don't rely on pointer comparisons List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, armbru@redhat.com, dgilbert@redhat.com makes it possible to copy error_abort pointers, not just pass them on directly. This is needed because follow-up patches add support for Error *local_err = ...; as a way to set an abort-on-error pointer, which requires that we have more than just a global error_abort abort-on-error pointer, but that any number of pointers all resolve to something specific. Add an assert statement when class is retrieved, to make sure we still get a core-dump if we (somehow) attempt to output the abort errp by mistake. Signed-off-by: Michael S. Tsirkin Reviewed-by: Eric Blake --- util/error.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/util/error.c b/util/error.c index 14f4351..e10cb34 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 == error_abort; +} 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(); } @@ -144,6 +150,7 @@ Error *error_copy(const Error *err) ErrorClass error_get_class(const Error *err) { + assert(err->err_class < ERROR_CLASS_MAX); return err->err_class; } @@ -168,7 +175,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) { -- MST