From: Junio C Hamano Date: Wed, 29 May 2024 17:43:47 GMT Subject: Re: [PATCH 05/19] reftable: improve const correctness when assigning string constants Message-ID: In-Reply-To: Patrick Steinhardt writes: > 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?