From patchwork Wed Jul 24 06:01:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 814126 Delivered-To: patch@linaro.org Received: by 2002:adf:f288:0:b0:367:895a:4699 with SMTP id k8csp2617557wro; Tue, 23 Jul 2024 23:03:40 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVBpqgNrkHC8okz49BV/wCl0h4GHlPW/V5oDDNn6WLXEQPxb4mXTTM4ubW5h9Qwey1w2xZP/Wl/jZeLo24GgG92 X-Google-Smtp-Source: AGHT+IEp0r6OFNYLkGILQ6/C9F8DHHFmrHQQk+Z5sZ9MzVKxZPf6cWohG2bfgal/bvIZb7YLM1aH X-Received: by 2002:adf:ab13:0:b0:368:3731:1614 with SMTP id ffacd0b85a97d-369bae25025mr6530528f8f.32.1721801019753; Tue, 23 Jul 2024 23:03:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721801019; cv=none; d=google.com; s=arc-20160816; b=VMULg7RS9QOpgwm7khsi1ZZ7NLR/ykUPf5f3krTiZeGNGaV1AN1GW4I5wq6U4hqEt9 dJWa+8BK3ErteySNyVxlNTAdmBBwo5qYW7JnBLxjePFjUMA15B0FQBiIkIkDd0WhBTqW lEMl6LZrcxYbzMFQwnyjd3D+pvyGLaPlew2Bq+CYqyw2aTOUWMl8RirHa1kLFIBvaVlE lnNRch7tQdh94jPhHosOUkX94CmuvZmKAL4sRSJQCUyFm1BSM+9zoo8czIkeOzGmwKOb 2m4xmQIKp2C60CNX7bswuiTaOLMumm2dixxBWT8QyAgVY0O1oxsDtSMX0js6b6G7YLwN 4E2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=p0BG8pFOrXYRqX1LnNUe0C7PL1AgkeMEZFJeVM/0Jrs=; fh=eimiGswTlodK8yi2DcDfSicmKwvq5bxKQKpD+SkkTNY=; b=W/9TWIEwOUBs/QX7TlU9qWabJr7AOyLdYftkAeWvTTeUQ6bdqvEYbxug6ERcHppiPw ZtPSw03FyJG74jMcA5CXWWtnGmo9VW0uAyVHVygVOdKj2KxBbN45NkIgxDYT+yRzl7Yw dE/3mODXl4m1N01lx32e0X1Bbxpga0eYm8gs4K517F+dkfcJv64WfP1Yyi7FzVUEJ//Q 3A0edvPRLq1J9gYxFwe2IgAzRfaCPfoplo0faszKWi7IpZ4+ARYQ+8qu/G/tHVBsaPZh uaYnbPxFVbj3R0+dP7AJb/S/QGdEcAE6Y86r4eeurJzAXFYDNzaC8y4ZqmhP0tI3cmBb +Agw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id ffacd0b85a97d-369e3837656si1374489f8f.907.2024.07.23.23.03.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jul 2024 23:03:39 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5725B88874; Wed, 24 Jul 2024 08:03:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id D4BEE88005; Wed, 24 Jul 2024 08:03:02 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id A9B6E88805 for ; Wed, 24 Jul 2024 08:02:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7EE181476; Tue, 23 Jul 2024 23:03:18 -0700 (PDT) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6C44B3F766; Tue, 23 Jul 2024 23:02:48 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt , Simon Glass , Marek Vasut , Mark Kettenis , Michal Simek , Patrick DELAUNAY , Patrice CHOTARD , Huan Wang , Angelo Dureghello , Daniel Schwierzeck , Thomas Chou , Rick Chen , Max Filippov , Sughosh Ganu Subject: [PATCH 02/40] lib: Handle a special case with str_to_list() Date: Wed, 24 Jul 2024 11:31:46 +0530 Message-Id: <20240724060224.3071065-3-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240724060224.3071065-1-sughosh.ganu@linaro.org> References: <20240724060224.3071065-1-sughosh.ganu@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean From: Simon Glass The current implementation can return an extra result at the end when the string ends with a space. Fix this by adding a special case. Signed-off-by: Simon Glass Signed-off-by: Sughosh Ganu --- lib/strto.c | 4 +++- test/str_ut.c | 4 +--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/strto.c b/lib/strto.c index 5157332d6c..f83ac67c66 100644 --- a/lib/strto.c +++ b/lib/strto.c @@ -236,12 +236,14 @@ const char **str_to_list(const char *instr) return NULL; /* count the number of space-separated strings */ - for (count = *str != '\0', p = str; *p; p++) { + for (count = 0, p = str; *p; p++) { if (*p == ' ') { count++; *p = '\0'; } } + if (p != str && p[-1]) + count++; /* allocate the pointer array, allowing for a NULL terminator */ ptr = calloc(count + 1, sizeof(char *)); diff --git a/test/str_ut.c b/test/str_ut.c index 389779859a..96e048975d 100644 --- a/test/str_ut.c +++ b/test/str_ut.c @@ -342,9 +342,7 @@ static int test_str_to_list(struct unit_test_state *uts) ut_asserteq_str("space", ptr[3]); ut_assertnonnull(ptr[4]); ut_asserteq_str("", ptr[4]); - ut_assertnonnull(ptr[5]); - ut_asserteq_str("", ptr[5]); - ut_assertnull(ptr[6]); + ut_assertnull(ptr[5]); str_free_list(ptr); ut_assertok(ut_check_delta(start));