From patchwork Wed May 22 01:19:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Crosthwaite X-Patchwork-Id: 245476 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 816F92C00A3 for ; Wed, 22 May 2013 11:23:47 +1000 (EST) Received: from localhost ([::1]:58392 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UexmL-0004ND-O6 for incoming@patchwork.ozlabs.org; Tue, 21 May 2013 21:23:45 -0400 Received: from eggs.gnu.org ([208.118.235.92]:44798) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uexm3-0004N8-Vl for qemu-devel@nongnu.org; Tue, 21 May 2013 21:23:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uexm2-0006KX-WC for qemu-devel@nongnu.org; Tue, 21 May 2013 21:23:27 -0400 Received: from mail-pd0-f170.google.com ([209.85.192.170]:36082) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uexm2-0006Hy-PV for qemu-devel@nongnu.org; Tue, 21 May 2013 21:23:26 -0400 Received: by mail-pd0-f170.google.com with SMTP id x10so1069747pdj.29 for ; Tue, 21 May 2013 18:23:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:mime-version :content-type:content-transfer-encoding:x-gm-message-state; bh=yr+lhPyoP6OooTOF7r7ZZ5XN5HJ3A1vbD0u6X5I8EaA=; b=IbnZiQFpp2Bn3CUXgYYDecMx9pSrYp3booTP+oEe7JoHylV9s76nBMjfH2T7tvKMeh CEYBOnqwBLl2ZVSR9Eaf1AbPYRNjry2lzie9/O1nbzKuoc5jw7CjKEyZpYPbU0WUgN+m xrN06BGJ0mSUn9JdLiyjods/NvPr5XDjQlStn/OiVdVcZbZYt3myndEljDrJOYPpuHkm zSB9dMASycIn6kmWF8yHUsq3fVrXr3GWjl19/66etgQ1GLbGzlY5vTT+oYA6xZVzx5eq zYSPddeMA+x+/g9C4wPImw9iZcS0LYamRrN5xP4w5eZxWS7xqqHv/A64/mWxFl8AM8BH sc+A== X-Received: by 10.68.236.68 with SMTP id us4mr4879087pbc.119.1369185805268; Tue, 21 May 2013 18:23:25 -0700 (PDT) Received: from localhost ([203.126.243.116]) by mx.google.com with ESMTPSA id fn9sm5620420pab.2.2013.05.21.18.23.21 for (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Tue, 21 May 2013 18:23:24 -0700 (PDT) From: peter.crosthwaite@xilinx.com To: qemu-devel@nongnu.org Date: Wed, 22 May 2013 11:19:16 +1000 Message-Id: <8e2bef6a55753869c50bfa32226f7fcf0439ca62.1369183592.git.peter.crosthwaite@xilinx.com> X-Mailer: git-send-email 1.8.3.rc1.44.gb387c77.dirty MIME-Version: 1.0 X-Gm-Message-State: ALoCoQnGAX9stfwnzDBwFEYQhzM2bUYB46WsQySFxLKAbpd1qSSpGBEZw8QwSkmSVl13ahfhPR5G X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.192.170 Cc: edgar.iglesias@gmail.com, aliguori@us.ibm.com, afaerber@suse.de, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH v2 1/1] qom/object: Don't poll cast cache for NULL objects 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: Peter Crosthwaite object_dynamic_cast_assert used to be tolerant of NULL objects and not assert. It's clear from the implementation that this is the expected behavior. The preceding check of the cast cache dereferences obj however causing a segfault. Fix by conditionalizing the cast cache logic on obj being non-null. Signed-off-by: Peter Crosthwaite Reviewed-by: Andreas Färber Reviewed-by: Anthony Liguori Reviewed-by: Paolo Bonzini Reviewed-by: Edgar E. Iglesias --- Changed from v1: Fixed 2 commit msg typos (AF review) qom/object.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qom/object.c b/qom/object.c index ec88231..803b94b 100644 --- a/qom/object.c +++ b/qom/object.c @@ -442,7 +442,7 @@ Object *object_dynamic_cast_assert(Object *obj, const char *typename, int i; Object *inst; - for (i = 0; i < OBJECT_CLASS_CAST_CACHE; i++) { + for (i = 0; obj && i < OBJECT_CLASS_CAST_CACHE; i++) { if (obj->class->cast_cache[i] == typename) { goto out; } @@ -458,7 +458,7 @@ Object *object_dynamic_cast_assert(Object *obj, const char *typename, assert(obj == inst); - if (obj == inst) { + if (obj && obj == inst) { for (i = 1; i < OBJECT_CLASS_CAST_CACHE; i++) { obj->class->cast_cache[i - 1] = obj->class->cast_cache[i]; }