From patchwork Fri Jul 5 17:03:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13725409 Received: from mout.web.de (mout.web.de [212.227.17.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F38A16EB47 for ; Fri, 5 Jul 2024 17:03:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720199034; cv=none; b=bynDddge7r4/6ehMPM8CueJoTtM0HkljneF4m7p5++9lDuDRpJqEefJxYXsbpbkkfMWXdePmrLZDvXBU4ixN2YfsaYfqegf/3yv56C9IU/sw9xRh292K0kyz8HK9Y23ANnTure2N6o2XRF1jsHaSE5AVw/zInqnjhNCowQO1LGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720199034; c=relaxed/simple; bh=p5Hl3qr626AhKrktHJJPZqcpJC3SbyWSZ+JCcQglROs=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=nw54z5plEjlG+HNGNycQb1inEluglitQen29iJL3i3/tlf7T8G7dn4rfzjhrAuFXAgxL5+5lHqmIMBBoD8K3gYT5671741ofUk94Gq0ceJN6pSp6A7JTXdjv8F5unOJGr8GSQOjRF0gCoWv95bLkjTdiRh/HBo2QVXQhQOFXTYo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de; spf=pass smtp.mailfrom=web.de; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b=O/4hsOGQ; arc=none smtp.client-ip=212.227.17.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b="O/4hsOGQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=web.de; s=s29768273; t=1720199017; x=1720803817; i=l.s.r@web.de; bh=b980dtSMZZc8e7eL62Y8/iZ204knM1gUohktE3WshL8=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:Subject:From:To: Cc:References:In-Reply-To:Content-Type:Content-Transfer-Encoding: cc:content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=O/4hsOGQp5UQGg/81l7OksyCf8vxRJab6W+OtL95mW58hVVkUPVCEuwccR0nbFPG vkcud1Z+Iksl+fZoc5F8Rys0G7pMG1GUn45UuEc6j9Zla4T80lrHAPwR+kJs9oyRr Nkd8spaZ94X0LhTgvELpH71C5iJQ6pMYLk/VRbuZHctLD87ZGtgoNDYwXYfG+xFBM RwGBnqmLkmVon9YKhH0Fmg2lCbooQVbE6KjX+GeurWwoWd72/vjCRhuO+TIiTJPwq ur2BoRCSv9XwK2nreXDI+BC16Y6fQjudCpjEXq6421c36l5VN5kglqsmo/LLCWd+2 WaKeUDqXXnv8BFhpuQ== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([91.47.153.221]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MeDQj-1rsdWI1ra3-00qYQR; Fri, 05 Jul 2024 19:03:37 +0200 Message-ID: <983be396-f47c-4573-8c33-af8367f8ddbe@web.de> Date: Fri, 5 Jul 2024 19:03:36 +0200 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2] t-strvec: use test_msg() From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Patrick Steinhardt , Phillip Wood , Eric Sunshine References: <35b0ba6b-d485-44f2-a19f-3ce816f8b435@web.de> Content-Language: en-US In-Reply-To: <35b0ba6b-d485-44f2-a19f-3ce816f8b435@web.de> X-Provags-ID: V03:K1:xV+O5o00taNiOMfMtRnU0ydMvZQjIOq3VnnDSlr2PBOzqTzqRKx RQ2/ktJQtLdnMNCNSJq/kIbYSHZcHsoIkZHJEWOdE0RC4IT9WFW8S6e0ovgUdPVw8AKCw87 /MQ2PiugwtZQ5gE0+E2x1gdh0T9Gab3jo2WHAoTWNhBks3e7QkJa0XFrILZ/1xGDFAP7Xm7 DyWhcGkMkEuub5rq1wnIQ== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:9mxSvAoCODk=;qw7i+M5faa+ZEvopxafahhoV0qb JDb7iZOzozof+O81Kc85Cr/S2SzsORbXiiGoNJeTE2Q7keD7Np6j7Qgd1GlJYqVc9tL2xBVYm DOcghroEtxR1bcdyCtSdNgFrauHKSkR1wy8pgaSuz/s+10JZbUYPNNzIRw293RuCNbXME0Ggy odS8fD9CutBQig5ILb6/HjXfnTfkMs05yJp6cdWv1e81cwyfER29FMIVpf57sPMKT8xaz/iTX Ouxu/S89NgC8E3edKiayMWPjtIa7ur7Wpi89ItYhgVPqQQNDWfmSI/VeB0CCkSlDmG0iwLMQB xEi+9ybyC7UyEp6mpJU4qO8N0/Ogc/14G1ncKpRB/7awAMl53e9K1h4oN8aHesNiYRUg9GEEf Tu/1G2MtPbmDqqqQyoHhchI7kv+TnTROAkmyscUF2EnJewec+QhbLWwv2W66ah5h3H+8g+XO6 7Nb8mvRRp5b1XhqjsHaXS9Ch5C/tY6GBST7Tr4wLz/IsnmY94N1N40n/gXR3oEGqKcqtR3SCo FQJu4j7X9UGmXLyKz8kRQEegcwWe772UkuOUZALxiSfqQSivAcWNGBX1EyPgesezmoVXVLgXd ue+StqcMZAsZOaXcztDuzTAjsZM8cu7UKSfqMhPGOtda/msxH/Dt2gCZqz7fpxqCyQSJ0FP8X zk9tcuNURK5hBaGs0S7cju+3lWdTVDPdop3mb4ddmBoSlruiegICVYdSmHmvWU5WyNkhYWI8Y /RUx94tKaxgD3LB87xZUYh2xvlRhKMCdfqTl4WwEqJP2VKdaVH4s6Ed3C3MEGd8P17ZTIE9HP ZUtUUHCdIXFc9AmZO/O5h+PLzx+eSogQWi6iME69tSjSo= check_strvec_loc() checks each strvec item by looping through them and comparing them with expected values. If a check fails then we'd like to know which item is affected. It reports that information by building a strbuf and delivering its contents using a failing assertion, e.g. if there are fewer items in the strvec than expected: # check "vec->nr > nr" failed at t/unit-tests/t-strvec.c:19 # left: 1 # right: 1 # check "strvec index 1" failed at t/unit-tests/t-strvec.c:71 Note that the index variable is "nr" and thus the interesting value is reported twice in that example (in lines three and four). Stop printing the index explicitly for checks that already report it. The message for the same condition as above becomes: # check "vec->nr > nr" failed at t/unit-tests/t-strvec.c:19 # left: 1 # right: 1 For the string comparison, whose error message doesn't include the index, report it using the simpler and more appropriate test_msg() instead. Report the index using its actual variable name and format the line like the preceding ones. The message for an unexpected string value becomes: # check "!strcmp(vec->v[nr], str)" failed at t/unit-tests/t-strvec.c:24 # left: "foo" # right: "bar" # nr: 0 Reported-by: Phillip Wood Signed-off-by: René Scharfe --- Changes since v1: - Typo fix. - Grammar fix. - Reworded problem description for brevity. - Qualify "name" in the last paragraph for clarity. - Add sign-off. - No code changes. Thank you, Eric! t/unit-tests/t-strvec.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) -- 2.45.2 diff --git a/t/unit-tests/t-strvec.c b/t/unit-tests/t-strvec.c index d4615ab06d..236203af61 100644 --- a/t/unit-tests/t-strvec.c +++ b/t/unit-tests/t-strvec.c @@ -17,12 +17,12 @@ static void check_strvec_loc(const char *loc, struct strvec *vec, ...) break; if (!check_uint(vec->nr, >, nr) || - !check_uint(vec->alloc, >, nr) || - !check_str(vec->v[nr], str)) { - struct strbuf msg = STRBUF_INIT; - strbuf_addf(&msg, "strvec index %"PRIuMAX, (uintmax_t) nr); - test_assert(loc, msg.buf, 0); - strbuf_release(&msg); + !check_uint(vec->alloc, >, nr)) { + va_end(ap); + return; + } + if (!check_str(vec->v[nr], str)) { + test_msg(" nr: %"PRIuMAX, (uintmax_t)nr); va_end(ap); return; } From patchwork Sun Jul 14 17:06:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13732757 Received: from mout.web.de (mout.web.de [212.227.15.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 147BD13BC02 for ; Sun, 14 Jul 2024 17:07:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720976825; cv=none; b=H0oOjHpWaubuWMpwJocFnAyxj7Lyd26/88lv1QadfLanb6JmXtrOIE62TIg6LqXcbNnrWDo+4eCy2+2gZgoRfvdIEkKnaBpElKvk/3XG41NM5ehhzWzwJcJLB4kkXf9g4Y3f6I3sxoRKqkaGiCcRjcZkJmNMz+sJAUf6uwyhF80= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720976825; c=relaxed/simple; bh=9q82KXBiZhTc3oQ+E65hCjDAnovDUd01OaXSsWiv4gs=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=M5LSAXtZo/8z79g+W7XK0ZULrSNEv24api8kEudjWh5/g4WJoVqZhELRFXcxr2y1+tu1jPziV5xa4ATckqsl/ROXHHDZVqdXWD3tGSo+1onM+1v2oh2C6AK5V6SZimMOQXJbpk+awkyjCNTGXYJWYAlgB8KHfaHbqs5y+V5iWEY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de; spf=pass smtp.mailfrom=web.de; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b=waCnsZrl; arc=none smtp.client-ip=212.227.15.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b="waCnsZrl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=web.de; s=s29768273; t=1720976811; x=1721581611; i=l.s.r@web.de; bh=7xVT1kMZaZxEcBI9hQO9zr7VuNhAP/Tp5LxtJjpgFXg=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:Subject:From:To: Cc:References:In-Reply-To:Content-Type:Content-Transfer-Encoding: cc:content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=waCnsZrl9uKypgXyv4U2nlY7jWv7HBO0oqkj0riCYOUkdqBKmCn6Z1olFydv29uI KDkLEeQrq37v8GRWC2w6e/9i1xm9jDJj0IcZ8nZhLO65H9Iw0B/LmjEtclnWT5YMx +Hikyc0GirTVD9TXRRl4acagDqGlsfiHlTJ507laTCiyY6cuNToVa6vBgpk0FaFCA dkqmIOI0BtgqXkQCFaRJM+DUAjpuho6SxP6DYKsYsv2gGCc/vBLzu1MM/V1VZRGqR 1qrfK94tjws7LgqUCjjO6KKCWXrvrUMfp6djAWzXI4FJhPPkc4RWgfG5KjC5biPjr 3eSpUZMBauY9vtBORw== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([91.47.153.221]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MIyeU-1snTFJ2i6s-00P3qY; Sun, 14 Jul 2024 19:06:51 +0200 Message-ID: Date: Sun, 14 Jul 2024 19:06:50 +0200 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 2/1] t-strvec: improve check_strvec() output From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List , Junio C Hamano Cc: Patrick Steinhardt , Phillip Wood , Eric Sunshine , Jeff King References: <35b0ba6b-d485-44f2-a19f-3ce816f8b435@web.de> <983be396-f47c-4573-8c33-af8367f8ddbe@web.de> Content-Language: en-US In-Reply-To: <983be396-f47c-4573-8c33-af8367f8ddbe@web.de> X-Provags-ID: V03:K1:UVIdXfd0BOkhLCMuYEFTQVKU1fzF336wCFrQWJv6bKTtzeynSUp xGpMiwQ+hM8A3/oL6kbyU6LMpd13TsoLeCd7Yohvg8FgMMhddtiycV4F7exiq14ta5li3DA fUgsqfBpXTvkVogdmO0jm31utGPqlULMNnLa8bIpVcQW2bYCQTkjSK7JLw+UbiprFqzNBpq pGMt5NVG8ucacaG+VyP/A== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:mICgL1lyP+Q=;qAC/D7qzyedIXw27apAU7gLU2ha Hrw9YzeNMfMCFzG72lGC4XT4iqG8oK38vyh65g3Gqkelz7Mgdj9057M1TngjQ3ibNlNW8WR37 vAgJ6kd8D8odipeamzvA2WQy10x5NgfVqT1oztrKuc4KHnO9uVgubOqpy/QWGVPevvm8g05y8 l4klIaDH18A93/YAuQemOodZM1B1XCjgqTovL1DeFvgt8qQsKMknjQehVh/wf1nKEjjmsgjs4 mEbAcnvqktvSsIdjr9+1AOxWHtpSzASC7ojElhYQPofgBnia/kNQcKA0uIXBJdy0JEh+1NhQL iEizEEseOysrAV4tDEBnwllMzaLwrDMrYO03r/UnEyKpdDTjuCpnI4qRIuxADYOOmnxkjXtns 6O6Izg+UIlOma5DzpSEsxYUb9Uo9K2MejI3QeeFCXaAautss/WLv2P3K0pnDqANta2GVU9cuv 75PbEmEOxb42xOB4ICZHWR3vdG1JnNj6mSv+8QesHQfK9SpAD3T1WbIDMCE5okh9MZoOO+lIS Nv++9+pHtkFtT0JHF6sQRjW902tPyMXwpZ9N8J+8NNA6FEPMirN1uewJ3mK0nRUm3J6STaOoc ZI6z8jRVPjoNrQf0SCtesgrK6Blij6c28eDim/kElt8yPbCXEVRniirbFus5lCut15E/ObF3u XN4ftma/IQDmAEailIVMIt1aretl4BP6ULapvZe1LWh/AEvNLXA6p+E1BixX7t9dE/ZZrPUs4 5SfM+O2NIBh5ew3RtOaX5qAUXzpK6S9DdmfRfanPy3o7jfoCBan6qD7fTDSjzTQlNUtGiSCxe BtoGmj+iYksQYJy8CpjMmzxA== The macro check_strvec calls the function check_strvec_loc(), which performs the actual checks. They report the line number inside that function on error, which is not very helpful. Before the previous patch half of them triggered an assertion that reported the caller's line number using a custom message, which was more useful, but a bit awkward. Improve the output by getting rid of check_strvec_loc() and performing all checks within check_strvec, as they then report the line number of the call site, aiding in finding the broken test. Determine the number of items and check it up front to avoid having to do them both in the loop and at the end. Sanity check the expected items to make sure there are any and that the last one is NULL, as the compiler no longer does that for us with the removal of the function attribute LAST_ARG_MUST_BE_NULL. Use only the actual strvec name passed to the macro, the internal "expect" array name and an index "i" in the output, for clarity. While "expect" does not exist at the call site, it's reasonably easy to infer that it's referring to the NULL-terminated list of expected strings, converted to an array. Here's the output with less items than expected in the strvec before: # check "vec->nr > nr" failed at t/unit-tests/t-strvec.c:19 # left: 1 # right: 1 ... and with the patch: # check "(&vec)->nr == ARRAY_SIZE(expect) - 1" failed at t/unit-tests/t-strvec.c:53 # left: 1 # right: 2 With too many items in the strvec we got before: # check "vec->nr == nr" failed at t/unit-tests/t-strvec.c:34 # left: 1 # right: 0 # check "vec->v[nr] == NULL" failed at t/unit-tests/t-strvec.c:36 # left: 0x6000004b8010 # right: 0x0 ... and with the patch: # check "(&vec)->nr == ARRAY_SIZE(expect) - 1" failed at t/unit-tests/t-strvec.c:53 # left: 1 # right: 0 A broken alloc value was reported like this: # check "vec->alloc > nr" failed at t/unit-tests/t-strvec.c:20 # left: 0 # right: 0 ... and with the patch: # check "(&vec)->nr <= (&vec)->alloc" failed at t/unit-tests/t-strvec.c:56 # left: 2 # right: 0 An unexpected string value was reported like this: # check "!strcmp(vec->v[nr], str)" failed at t/unit-tests/t-strvec.c:24 # left: "foo" # right: "bar" # nr: 0 ... and with the patch: # check "!strcmp((&vec)->v[i], expect[i])" failed at t/unit-tests/t-strvec.c:53 # left: "foo" # right: "bar" # i: 0 If the strvec is not NULL terminated, we got: # check "vec->v[nr] == NULL" failed at t/unit-tests/t-strvec.c:36 # left: 0x102c3abc8 # right: 0x0 ... and with the patch we get the line number of the caller: # check "!strcmp((&vec)->v[i], expect[i])" failed at t/unit-tests/t-strvec.c:53 # left: "bar" # right: NULL # i: 1 check_strvec calls without a trailing NULL were detected at compile time before: t/unit-tests/t-strvec.c:71:2: error: missing sentinel in function call [-Werror,-Wsentinel] ... and with the patch it's only found at runtime: # check "expect[ARRAY_SIZE(expect) - 1] == NULL" failed at t/unit-tests/t-strvec.c:53 # left: 0x100e5a663 # right: 0x0 We can let check_strvec add the terminating NULL for us and remove it from callers, making it impossible to forget. Leave that conversion for a future patch, though, since this reimplementation is already intrusive enough. Reported-by: Jeff King Signed-off-by: René Scharfe --- For next, on top of c6f35e529e t-strvec: use test_msg(). t/unit-tests/t-strvec.c | 46 +++++++++++++---------------------------- 1 file changed, 14 insertions(+), 32 deletions(-) -- 2.45.2 diff --git a/t/unit-tests/t-strvec.c b/t/unit-tests/t-strvec.c index 236203af61..fdb28ba220 100644 --- a/t/unit-tests/t-strvec.c +++ b/t/unit-tests/t-strvec.c @@ -3,38 +3,20 @@ #include "strvec.h" #define check_strvec(vec, ...) \ - check_strvec_loc(TEST_LOCATION(), vec, __VA_ARGS__) -LAST_ARG_MUST_BE_NULL -static void check_strvec_loc(const char *loc, struct strvec *vec, ...) -{ - va_list ap; - size_t nr = 0; - - va_start(ap, vec); - while (1) { - const char *str = va_arg(ap, const char *); - if (!str) - break; - - if (!check_uint(vec->nr, >, nr) || - !check_uint(vec->alloc, >, nr)) { - va_end(ap); - return; - } - if (!check_str(vec->v[nr], str)) { - test_msg(" nr: %"PRIuMAX, (uintmax_t)nr); - va_end(ap); - return; - } - - nr++; - } - va_end(ap); - - check_uint(vec->nr, ==, nr); - check_uint(vec->alloc, >=, nr); - check_pointer_eq(vec->v[nr], NULL); -} + do { \ + const char *expect[] = { __VA_ARGS__ }; \ + if (check_uint(ARRAY_SIZE(expect), >, 0) && \ + check_pointer_eq(expect[ARRAY_SIZE(expect) - 1], NULL) && \ + check_uint((vec)->nr, ==, ARRAY_SIZE(expect) - 1) && \ + check_uint((vec)->nr, <=, (vec)->alloc)) { \ + for (size_t i = 0; i < ARRAY_SIZE(expect); i++) { \ + if (!check_str((vec)->v[i], expect[i])) { \ + test_msg(" i: %"PRIuMAX, i); \ + break; \ + } \ + } \ + } \ + } while (0) static void t_static_init(void) { From patchwork Sun Jul 14 17:06:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13732758 Received: from mout.web.de (mout.web.de [212.227.15.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4043C139CFF for ; Sun, 14 Jul 2024 17:07:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720976833; cv=none; b=fiD5+BBWB9lqQKBx1s9tQRXXlsCLJvpLmIZVmTRy5r//xgQFq26epkdlyYsUdcLvp6D7EpCJXf92ftazNYy+DhZNf1rcVs7R/+qsrGOxwdVQ/95p/K6zF31K8ZH2Tj4RrGGAVTsbUAmKDV88c34Pr6reqswPVAtDm5VcrsLcVF4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720976833; c=relaxed/simple; bh=ZUlzLBQP6Q+7mNfA2rPu4UhqhVVZ+kUxOvpAiWtVI+Y=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=Qf0fstI8Nld3RRzIVw4G4aZI1Yjq+AlQI9INLJjGF4GNLRXSfF8cSX7FmzFur2uW8CbkAokho6gNZUW1O0eFx3nQqJ0yCOLt03lXSaBFbOA7Yzm+7PGmo0X1Cck2U1SNJQCHDFHAlvRvmLq39wiKKvBuxzLzMFGsfuUE4EbNxik= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de; spf=pass smtp.mailfrom=web.de; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b=aAZsC+Ms; arc=none smtp.client-ip=212.227.15.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b="aAZsC+Ms" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=web.de; s=s29768273; t=1720976819; x=1721581619; i=l.s.r@web.de; bh=+vbNgs09UKI7+3D2vIHYeGhbBeTELzUE+uGHl88xP3o=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:Subject:From:To: Cc:References:In-Reply-To:Content-Type:Content-Transfer-Encoding: cc:content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=aAZsC+MssgxIpPOt5eLerlLjNLBKaCS8FRnE0wndRWunNIpQOQjAGMj2CVI8Sp0a xktLhhasrhPbL8CDw52EaO3rVjorMjPyvcvQdIWdvKlraQWe5edh4BMNMYizWApV+ gVgr9JLoOVnOqEM04xiTzlGjZJQX2iFXyvZp7/616TZdl/h67fVaNuCB9Ewl3rBbl zJlDL4AG1wXyEOIYZ3muAxeMEBd+RH6CsyWOb4VnH90s6S/+azc3JM0UBuAziBNdo VTreMcME4wpHhwODflXZsxZNBEqalvi8Rt5w4BFI3NKwXYocutynknlCtcBpKSrGF KK3exLycKwCh6y5gXQ== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([91.47.153.221]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MfKxj-1rsdKq05EZ-00hYUI; Sun, 14 Jul 2024 19:06:59 +0200 Message-ID: <075b3d08-4270-4064-8103-1fece055e197@web.de> Date: Sun, 14 Jul 2024 19:06:58 +0200 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 3/1] t-strvec: tighten .alloc check in check_strvec From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List , Junio C Hamano Cc: Patrick Steinhardt , Phillip Wood , Eric Sunshine , Jeff King References: <35b0ba6b-d485-44f2-a19f-3ce816f8b435@web.de> <983be396-f47c-4573-8c33-af8367f8ddbe@web.de> Content-Language: en-US In-Reply-To: <983be396-f47c-4573-8c33-af8367f8ddbe@web.de> X-Provags-ID: V03:K1:rUZcGLCQWLmVC59O4e1WHcmAcuU+oeW6KI9KC3MapeoiSkYWA/3 vv+Dsb5A2yHqomwuTxQVyxUZepE5uW2lNUizz+XleN6JLHddq7w2n2QiCWx+mnarcXhFhva DttyJhy3zErPVIDK7kaDddoJbY+Roy3FwRHpWu4j7986PVOTCrkQqAuSv5dPg55pEd169j/ XHVPiw4393xElrncsDq9w== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:xqhFln93png=;OcWJ9T9MFionD0udJkyNefJYGLA ZlBg4kgn51p+Xr950UNh4kWMEiiO5k+PEZZPRlDY6uhOsbl/PIOPZyCYdR9Bs8u59Zk/dXc5W rF597+4luCyU4uQ9/TnHGMHZg02lpwWibgJ5Y+Tr5PpWO6yw4gu8tuoYAOjr7NTFBgUmZbAZ1 tLm6GXsIp6FFw5rEZahxlTvh0RdDyt0dUGcSiijvD0kGE4R1zeD5RQGHa2aIQR9mMOCeKwfwP Yo8VFufoCSC3xDK8BjxhlgvuNbPLtCMtqMalR8+1CFiHlfS6SR0XnPwYJdGXu41rvkqDELiAr xgRIHIN3RbAfpSYexZKUhGYyNICKhePelB9T7sjX4cYGVVMr8vc5Qd2lcrD/jVsVq0SCOyoCQ Q5ffqR7JdgeHP4ULbwfTGvh0LFimWOVWaqZWdMyylQ0sQK/9hv6p3KZfv+8VmEHJazu5rMRr8 VfsWYgvAaKBV7L/9wu2T5bbKBM/yA/1nnkG9frJbbNZLcA6gj4hMO0NBOG6jipcnjv53D4MPE B31eogzJ3eLlRVjEwdyTxEbeoo/3Hxpaiwq4sWGttPu9vVZW3JWFWPFML7IPbGiDngN2n3ke4 oDNLwtZrkwGcoFMc7AhOr7TmzWTaCdoGL1Q0t3BQXvzOJ50gdiUbub6h14vh4A2+Y1YCfvXCI 6NRTk7pNzJ/Gh5Wsf0J6k6QrZZssK6IjJTxrM85BOffgi7g/av0Rty6u4iVuK5TR1tBSWerbs 7EMj40VsB/SzfFYAeQsTw2WGXVGhAOWv+pTw7KVTaUXEGp/cp6mNlo619UtroGupxrK0nr5dW EZRs12WyEJq93c6BrWCpWRtQ== The members .nr and .alloc of an empty strvec are both zero and the trailing NULL is provided by the shared global variable empty_strvec. Once at least one item is added, .alloc needs to be bigger than .nr to leave room for the terminating NULL. The current .alloc check only tests whether it's bigger or equal to .nr in all cases. Tighten it depending on whether the strvec is backed by empty_strvec or not. A report for a non-zero .alloc in an empty strvec looks like this: # check "(&vec)->nr == (&vec)->alloc" failed at t/unit-tests/t-strvec.c:55 # left: 0 # right: 1 And .alloc being .equal to .nr in a non-empty strvec results in: # check "(&vec)->nr < (&vec)->alloc" failed at t/unit-tests/t-strvec.c:55 # left: 1 # right: 1 Signed-off-by: René Scharfe --- Bonus patch. t/unit-tests/t-strvec.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.45.2 diff --git a/t/unit-tests/t-strvec.c b/t/unit-tests/t-strvec.c index fdb28ba220..6a4d425840 100644 --- a/t/unit-tests/t-strvec.c +++ b/t/unit-tests/t-strvec.c @@ -8,7 +8,9 @@ if (check_uint(ARRAY_SIZE(expect), >, 0) && \ check_pointer_eq(expect[ARRAY_SIZE(expect) - 1], NULL) && \ check_uint((vec)->nr, ==, ARRAY_SIZE(expect) - 1) && \ - check_uint((vec)->nr, <=, (vec)->alloc)) { \ + ((vec)->v == empty_strvec ? \ + check_uint((vec)->nr, ==, (vec)->alloc) : \ + check_uint((vec)->nr, <, (vec)->alloc))) { \ for (size_t i = 0; i < ARRAY_SIZE(expect); i++) { \ if (!check_str((vec)->v[i], expect[i])) { \ test_msg(" i: %"PRIuMAX, i); \