[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] Modifying a char pointer initialized by character str
Re: [Tinycc-devel] Modifying a char pointer initialized by character string literal should cause an error.
Fri, 27 Dec 2019 19:12:54 +0100
On Fri, Dec 27, 2019 at 10:26:24PM +0800, 瞿兴 wrote:
> In section 6.7.8 of the C99 draft document defines :
> If an attempt is made to use pointer variable p to modify the contents of the
> array, the behavior is undefined.
> When executing the testcase(in the attachment), tinyc does not report an
> error and modify the value of the variable NISLParameter0 successfully
Well, "undefined behavior" allows tinycc to do this.
> The attachment includes the relevant testcase.
IMHO the only thing tinycc should do is to warn that a const char * has
been implicitly cast to char * in the initialization of NISLParameter0.
Putting string literals into read-only sections is a nice to have.
> char *NISLParameter0 = "abcdefghij";