Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp2576318rdg; Mon, 14 Aug 2023 07:02:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFvUagbvbLReGelTjFiNW/StUIgZ1Tpr8m2mag9LQbnQR9/QhM/dXOmC4bJXnnHRU3qv+PD X-Received: by 2002:a05:6402:191:b0:523:264e:eee3 with SMTP id r17-20020a056402019100b00523264eeee3mr8009175edv.11.1692021759717; Mon, 14 Aug 2023 07:02:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692021759; cv=none; d=google.com; s=arc-20160816; b=0Z5OikttiZMlS5c5bM09/g9MskV/AcPbK/TQNx7wdVKyLVJNzoRzibHB2c1VUIfmbo /kzBhyVsX4tAzi+4vPKl906qkU0mnXp08CqATsGlpeXJBNooFIFKQrqkSazgrYDnIkmq gdFZtl6qovOIgrKM5uUpwhZjdBCYn+My+Vep+NYhZzrL3edWB3WNZrgF6aassQPUml6n hPS6OhzlgOLy1jyoyKjMj7s35+2R0K5zRJsy7rS8RP0rADlU7mtYK3pEq2535rsY2Rzz QK9isHM9kCtNtr2wRBi/T6BqBHF4vl8g4fUsZbi15p24stYcxtrV1XlF2nV+1lwKWGNZ 6x6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Tu5hYj0cENcnReD71Hf/Ug24TIdVaaEFqB1yCIa77wM=; fh=bGF4ESczbIrmrNxFOdEMfzJNgTVkRsqDRt+LRN0CeSg=; b=Z+QIhQx8/bQFK7mVDsm7PkQiaq5AgTfQMakqsamXVl5iQqR1MVPdT4TO4FXlyT1S1e eIGldnBZ4lKhaAh9bwktkgAVeZ9T02jYsIxo/K3rGYq6MB/uvMKr88jDu2wk8W6Z8n/p naD6BbusDTi2JFiano9mcMTgIO1UxnAYn6QmIqrda1mvoTCd7UTb5hymkpIv9fAmpi4b yKVRXS6kLISQLOfQJqYXL5x/ZZtFTXPG2sHGllWNrMEk2Jimy4aNQYkK9/8/f0l7D+I6 J7yZ6LxsbVLo/yrU8lzjYvAMef1q6PEf3XSv9uSNNWulIJS7FwHAth6kcVGsoexuMiE7 VymQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=PzkquUQP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b3-20020aa7cd03000000b005256b963009si939624edw.663.2023.08.14.07.02.11; Mon, 14 Aug 2023 07:02:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=PzkquUQP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230380AbjHNNXx (ORCPT + 99 others); Mon, 14 Aug 2023 09:23:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230450AbjHNNXf (ORCPT ); Mon, 14 Aug 2023 09:23:35 -0400 Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA20810E4; Mon, 14 Aug 2023 06:23:33 -0700 (PDT) Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 37E5t3EI003856; Mon, 14 Aug 2023 08:23:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= PODMain02222019; bh=Tu5hYj0cENcnReD71Hf/Ug24TIdVaaEFqB1yCIa77wM=; b= PzkquUQPH3Be0u83loyK39r6rppogO3iGnV+BlckNjHR0L2gaIKJwpMcLtaesb2u XRue+MEB6BFUFRceCI+ME7tkGYz078i73BA6DY5ZYwkPVK6caRt/P0x+L6k8mgt4 5kGaYHr30877M3kqDqDKSd+l1fl1NU62oapXNcDtzBaNwcCDaLMtLP7M+4onbI2A PA1gqOHlL4+ilrFunXdFt9W3BB2cKCU1XmNNKQ+pEpUpYsbeHAvOb/Da29psqv1r j0HeCrepdNcRrpibF5fUDyF035WqbF1uHZhtCZwQlr7aqTtFi02Ze1J2ifzdxdwD qmrpQofOePddkwJb4J04xg== Received: from ediex02.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3se8kqt6x8-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 14 Aug 2023 08:23:15 -0500 (CDT) Received: from ediex02.ad.cirrus.com (198.61.84.81) by ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Mon, 14 Aug 2023 14:23:12 +0100 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by anon-ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server id 15.2.1118.30 via Frontend Transport; Mon, 14 Aug 2023 14:23:12 +0100 Received: from EDIN4L06LR3.ad.cirrus.com (EDIN4L06LR3.ad.cirrus.com [198.61.65.68]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 5AF99458; Mon, 14 Aug 2023 13:23:12 +0000 (UTC) From: Richard Fitzgerald To: , , CC: , , , , Richard Fitzgerald Subject: [PATCH v4 02/10] kunit: string-stream: Don't create a fragment for empty strings Date: Mon, 14 Aug 2023 14:23:01 +0100 Message-ID: <20230814132309.32641-3-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230814132309.32641-1-rf@opensource.cirrus.com> References: <20230814132309.32641-1-rf@opensource.cirrus.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: D4ds0hHj5j_C3xMvSDa2VQ9hXlvwwMec X-Proofpoint-GUID: D4ds0hHj5j_C3xMvSDa2VQ9hXlvwwMec X-Proofpoint-Spam-Reason: safe X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the result of the formatted string is an empty string just return instead of creating an empty fragment. Signed-off-by: Richard Fitzgerald --- lib/kunit/string-stream.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/kunit/string-stream.c b/lib/kunit/string-stream.c index cc32743c1171..ed24d86af9f5 100644 --- a/lib/kunit/string-stream.c +++ b/lib/kunit/string-stream.c @@ -50,11 +50,17 @@ int string_stream_vadd(struct string_stream *stream, /* Make a copy because `vsnprintf` could change it */ va_copy(args_for_counting, args); - /* Need space for null byte. */ - len = vsnprintf(NULL, 0, fmt, args_for_counting) + 1; + /* Evaluate length of formatted string */ + len = vsnprintf(NULL, 0, fmt, args_for_counting); va_end(args_for_counting); + if (len == 0) + return 0; + + /* Need space for null byte. */ + len++; + frag_container = alloc_string_stream_fragment(stream->test, len, stream->gfp); -- 2.30.2