From patchwork Fri Sep 26 05:18:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Crosthwaite X-Patchwork-Id: 393520 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 DEEF41400F4 for ; Fri, 26 Sep 2014 15:20:21 +1000 (EST) Received: from localhost ([::1]:44730 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XXNx6-0000v0-1Q for incoming@patchwork.ozlabs.org; Fri, 26 Sep 2014 01:20:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40286) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XXNwZ-0008UY-29 for qemu-devel@nongnu.org; Fri, 26 Sep 2014 01:19:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XXNwC-0005As-Br for qemu-devel@nongnu.org; Fri, 26 Sep 2014 01:19:46 -0400 Received: from mail-pa0-f42.google.com ([209.85.220.42]:41292) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XXNwC-00056s-7S for qemu-devel@nongnu.org; Fri, 26 Sep 2014 01:19:24 -0400 Received: by mail-pa0-f42.google.com with SMTP id bj1so1751109pad.1 for ; Thu, 25 Sep 2014 22:19:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=8JoCJWaDd7jAgzqexijfzkN/J5GV/2LzvTb7D6mdQOY=; b=hWlQHoYAX0ELeXFscjfa8alxZ49II2OdZoSWuQv+ykjhJ4cnSj0qa4rFfo8Uhi7yDm X/SZf4IMt5sSu5nPnUVGnSdIagYbHpjCsdR/OAFD8NtfGW7aCfM/eI9Zr37DpAysjgat QnB3c8eIUxyBjaILYcUFgEse8jr1lytFWUNXPvlhZoDdGA3pqPz6LWaTDRTmU7lnkOwH bkYsxrHyaqiWESMzezGSHVzbPZWmIqFlfuHHt+J7FcAUKCEjRzyNvV/CHgMXVkQFxsDl WJJO2pkm9jg8megHQ0qt5wHeS9VOQgoJe86k89zo32Itn+MeSpDKBZg6ejJiCHuRRIRx lUsA== X-Gm-Message-State: ALoCoQlMk6nCzH0tJW9ehQdEvG507vImfkQGyECK84HfE+IiERuuOxbkB41pRI/v11n12wV78AHB X-Received: by 10.70.53.35 with SMTP id y3mr34079895pdo.43.1411708758535; Thu, 25 Sep 2014 22:19:18 -0700 (PDT) Received: from localhost ([149.199.62.254]) by mx.google.com with ESMTPSA id fu3sm3728149pdb.27.2014.09.25.22.19.17 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 25 Sep 2014 22:19:18 -0700 (PDT) From: Peter Crosthwaite To: qemu-devel@nongnu.org Date: Thu, 25 Sep 2014 22:18:47 -0700 Message-Id: <082b20c6ae4ab03961beb8a174c4ea7055a98518.1411703316.git.peter.crosthwaite@xilinx.com> X-Mailer: git-send-email 2.1.0.1.g27b9230 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.220.42 Cc: peter.maydell@linaro.org, pbonzini@redhat.com, agraf@suse.de, afaerber@suse.de Subject: [Qemu-devel] [PATCH qom v3 04/14] qmp: qstring: Handle NULL strings 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 Create a valid qobject even if the input string is null. qstring->string will be NULL and length will be 0. This prepares support for clearing of QOM Link properties where NULL canonical path string will be passes through this API. Reviewed-by: Alexander Graf Signed-off-by: Peter Crosthwaite --- qobject/qstring.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/qobject/qstring.c b/qobject/qstring.c index 607b7a1..a15ffed 100644 --- a/qobject/qstring.c +++ b/qobject/qstring.c @@ -48,14 +48,16 @@ QString *qstring_from_substr(const char *str, int start, int end) { QString *qstring; - qstring = g_malloc(sizeof(*qstring)); + qstring = g_malloc0(sizeof(*qstring)); qstring->length = end - start + 1; qstring->capacity = qstring->length; - qstring->string = g_malloc(qstring->capacity + 1); - memcpy(qstring->string, str + start, qstring->length); - qstring->string[qstring->length] = 0; + if (str) { + qstring->string = g_malloc(qstring->capacity + 1); + memcpy(qstring->string, str + start, qstring->length); + qstring->string[qstring->length] = 0; + } QOBJECT_INIT(qstring, &qstring_type); @@ -69,7 +71,7 @@ QString *qstring_from_substr(const char *str, int start, int end) */ QString *qstring_from_str(const char *str) { - return qstring_from_substr(str, 0, strlen(str) - 1); + return qstring_from_substr(str, 0, (str ? strlen(str) : 0) - 1); } static void capacity_increase(QString *qstring, size_t len)