Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

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

qu__xing
Beginner
429 Views

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
429 Views

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

0 Kudos
qu__xing
Beginner
429 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?

0 Kudos
Viet_H_Intel
Moderator
429 Views

No, it's for internal only. 

0 Kudos
qu__xing
Beginner
429 Views

Okay, thank you.

0 Kudos
Reply