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 below, icc does not report an error or modify the value of the variable NISLParameter0 while other compilers such as gcc and clang report runtime errors: “Segmentation fault”. I think it would be better for intelc to throw an error or at least a warning for the wrong action.
The OS is:
Linux version 4.15.0-65-generic
The GCC version in path is :
gcc (GCC) 7.3.0
TestCase:
#include<stdio.h>
char *function(char *buf){
int i = 5;
buf[5] = '1';
return buf;
}
int main(void){
char *NISLParameter0 = "abcdefghij";
char *NISLParameter1 = function(NISLParameter0);
printf("%s\n", NISLParameter1);
return 0;
}
Compiler Version:
icc (ICC) 19.0.4.243 20190416
Output:
abcdefghij
Expected output:
Throw an error or at least a warning.