Hi,

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 while other 
compilers such as gcc and clang report a runtime error: “Segmentation fault”. I 
think it would be better for tinyc to throw an error or at least a warning for 
the wrong action.

 

The OS is:

Linux version 4.15.0-65-generic

 

Compiler Version:

tcc version 0.9.27 (x86_64 Linux)

 

Output:

111

abcde1ghij

 

Expected output:

Throw an error or at least a warning.

 

The attachment includes the relevant testcase. Looking forward to your reply.
#include<stdio.h>
char *function(char *buf){
    buf[5] = '1';
    printf("%d\n", 111);
    return buf;
}
int main(void){
    char *NISLParameter0 = "abcdefghij";
    char *NISLParameter1 = function(NISLParameter0);
    printf("%s\n", NISLParameter1);
    return 0;
}
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to