Community
cancel
Showing results for 
Search instead for 
Did you mean: 
qu__xing
Beginner
99 Views

Modifying a char pointer initialized by character string literal should cause an error.

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.

0 Kudos
4 Replies
Viet_H_Intel
Moderator
99 Views

Thanks for reporting this issue. I've opened a case (CMPLRIL0-32347) with our Developer. 

qu__xing
Beginner
99 Views

Thanks for looking into this problem.

And how can i track this issue?  Is intelc's bug tracking system open to the outside world?

Viet_H_Intel
Moderator
99 Views

No, it's for internal only. 

qu__xing
Beginner
99 Views

Okay, thank you.

Reply