Re: [PATCH v2 3/4] strbuf_setlen: don't write to strbuf_slopbuf

2 messages, 2 authors, 2017-08-23 · open the first message on its own page

Re: [PATCH v2 3/4] strbuf_setlen: don't write to strbuf_slopbuf

From: Junio C Hamano <hidden>
Date: 2017-08-23 22:24:30

Brandon Casey [off-list ref] writes:
On Wed, Aug 23, 2017 at 2:04 PM, Junio C Hamano [off-list ref] wrote:
quoted
Brandon Casey [off-list ref] writes:
quoted
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 = "";
Rather, more like "const char slopbuf[1];"

Re: [PATCH v2 3/4] strbuf_setlen: don't write to strbuf_slopbuf

From: Brandon Casey <hidden>
Date: 2017-08-23 22:39:31

On Wed, Aug 23, 2017 at 3:24 PM, Junio C Hamano [off-list ref] wrote:
Brandon Casey [off-list ref] writes:
quoted
On Wed, Aug 23, 2017 at 2:04 PM, Junio C Hamano [off-list ref] wrote:
quoted
Brandon Casey [off-list ref] writes:
quoted
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 = "";
Rather, more like "const char slopbuf[1];"
You'd think that would be sufficient right?  Apparently gcc and clang
will only place a variable marked as const in the read-only section if
you initialize it with a constant too.  (gcc 4.9.2, clang 3.8.1 on
linux, clang 8.1.0 on osx)

I might have to adjust my stance on initializing global variables
moving forward :-)

-Brandon
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help