From patchwork Fri Aug 15 05:31:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Crosthwaite X-Patchwork-Id: 380080 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 240AA140090 for ; Fri, 15 Aug 2014 15:32:49 +1000 (EST) Received: from localhost ([::1]:57564 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIA87-0006Tm-BW for incoming@patchwork.ozlabs.org; Fri, 15 Aug 2014 01:32:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49865) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIA7X-0005XF-EJ for qemu-devel@nongnu.org; Fri, 15 Aug 2014 01:32:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XIA7R-0003ix-6r for qemu-devel@nongnu.org; Fri, 15 Aug 2014 01:32:11 -0400 Received: from mail-pa0-f48.google.com ([209.85.220.48]:38722) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIA7R-0003it-29 for qemu-devel@nongnu.org; Fri, 15 Aug 2014 01:32:05 -0400 Received: by mail-pa0-f48.google.com with SMTP id et14so2914006pad.7 for ; Thu, 14 Aug 2014 22:32:04 -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=79nzdcFlE4OHq2Vaqio6HotSQjOmCMYguVhzhm8QZ0E=; b=UY257DK/aWWopOOcps52gyH5RQxQHko8RDYsJRuv5Cp2RRNNNLp3++Mmhaomh2lZeM BAPIEgzuUlmnu8zADeLo39zscnlW0EIYggGocmH2+kvundGzIj+b4yc7NDRs8r3lxPcS StOmfdMjIeClUJhd7+SbbSsb/Ox77ZDRVSt/eaKSXIipIYdB/bVZImpTFAFcZxyRL786 V82vI4LnQ/LzLu7brqq2Oq7i/usA5/3WeU1UM1GCLoKz775GQ5WLL4VAh8pRo695hFhL yKwM6knM/oxemf45pQ3cFHMbI7p4goGyn5HkojJxZt+pHBrBR2q55j0xC2CQERei0zQI +dkw== X-Gm-Message-State: ALoCoQmRoivB0odzX+YVoEnThZEm0RijGgHpmt+WwCSLcgcA8o2LyLlqT9qVUfWmE7XsfvkstZ+p X-Received: by 10.68.87.65 with SMTP id v1mr9412152pbz.118.1408080724231; Thu, 14 Aug 2014 22:32:04 -0700 (PDT) Received: from localhost ([149.199.62.254]) by mx.google.com with ESMTPSA id ki7sm7002657pbc.65.2014.08.14.22.32.03 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 14 Aug 2014 22:32:03 -0700 (PDT) From: Peter Crosthwaite To: qemu-devel@nongnu.org Date: Thu, 14 Aug 2014 22:31:32 -0700 Message-Id: <695a7681d4889b0cb6a0611aa6afcb7bc306803f.1408080397.git.peter.crosthwaite@xilinx.com> X-Mailer: git-send-email 2.0.1.1.gfbfc394 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.48 Cc: peter.maydell@linaro.org, pbonzini@redhat.com, agraf@suse.de, afaerber@suse.de Subject: [Qemu-devel] [PATCH v2 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. 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)