Re: [PATCH] strbuf_grow(): maintain nul-termination even for new buffer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thomas Rast <trast@xxxxxxxxxxxxxxx> writes:

> So make sure that strbuf_grow() puts in a nul even if it has nowhere
> to copy it from.  This makes strbuf_grow(sb, 0) a semantic no-op as
> far as readers of the buffer are concerned.

Makes sense, thanks.

> Also remove the nul-termination added by strbuf_init, which is made
> redudant.

Ok.

This is a tangent but if we do not have hint, we point at strbuf_slopbuf[]
which is:

    /*
     * Used as the default ->buf value, so that people can always assume
     * buf is non NULL and ->buf is NUL terminated even for a freshly
     * initialized strbuf.
     */
    char strbuf_slopbuf[1];

While nobody should be writing into it, we do not really enforce the
constness of this buffer.

I wonder if it would be worth making this into "const char []" and have
the complier/linker move it to read-only section to catch potential bugs.



--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]