Re: [PATCH 05/19] reftable: improve const correctness when assigning string constants
- From
Junio C Hamano <gitster@pobox.com>
- Date
- May 29, 2024, 17:43 UTC
- Message-ID
- <xmqqed9ky0mk.fsf@gitster.g>
- In-Reply-To
- <dc5d85257eef747f2331638ed718b0f7a5bb1da2.1716983704.git.ps@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 13 quoted lines
> diff --git a/reftable/basics_test.c b/reftable/basics_test.c
> index 997c4d9e01..af9209d535 100644
> --- a/reftable/basics_test.c
> +++ b/reftable/basics_test.c
> @@ -58,8 +58,8 @@ static void test_binsearch(void)
>
> static void test_names_length(void)
> {
> - char *a[] = { "a", "b", NULL };
> - EXPECT(names_length(a) == 2);
> + char *names[] = { (char *)"a", (char *)"b", NULL };
> + EXPECT(names_length(names) == 2);
> }I would have preferred to see this kind of rewrite more than separate and clearly writable variables that are initialied with the constant contents e.g. branches[] = "refs/heads/*", we saw in earlier steps. Wouldn't that approach, combined with making the literal constants stored in read-only segment to trigger runtime failure when a bug causes the "unfortunately non-const" variables to be written, give us a better result?