Re: [PATCH v2 3/4] strbuf_setlen: don't write to strbuf_slopbuf
- From
Brandon Casey <drafnel@gmail.com>
- Date
- Aug 23, 2017, 22:11 UTC
- Message-ID
- <CA+sFfMf7nerBhm5jZ+sDJdGbTbLz_JXyqkSPGOA8o9mOE-7Khg@mail.gmail.com>
- In-Reply-To
- <CA+sFfMdMgrGBhECegBe09c38nRM+Zt5JK4gJaZ96DO-9zC-8qA@mail.gmail.com>
On Wed, Aug 23, 2017 at 2:54 PM, Brandon Casey <drafnel@gmail.com> wrote:
Show 14 quoted lines
> On Wed, Aug 23, 2017 at 2:20 PM, Brandon Casey <drafnel@gmail.com> wrote: >> On Wed, Aug 23, 2017 at 2:04 PM, Junio C Hamano <gitster@pobox.com> wrote: >>> Brandon Casey <drafnel@gmail.com> writes: >>> >>>> So is there any reason why didn't do something like the following in >>>> the first place? >>> >>> My guess is that we didn't bother; if we cared, we would have used a >>> single instance of const char in a read-only segment, instead of >>> such a macro. >> >> I think you mean something like this: >> >> const char * const strbuf_slopbuf = "";
Hmm, apparently it is sufficient to mark our current strbuf_slopbuf array as const and initialize it with a static string to trigger its placement into the read-only section by gcc (and clang).
const char strbuf_slopbuf[1] = "";
-Brandon