Search

Vs2010 x64 C and C++ program crashes when string literal are not modified by Vipin Jain

Closed
as Fixed Help for as Fixed

7
0
Sign in
to vote
Type: Bug
ID: 577724
Opened: 7/23/2010 7:40:10 AM
Access Restriction: Public
1
Workaround(s)
2
User(s) can reproduce this bug
Program is crashing even though it does not modify the string literal when compiled with VS2010 native x64 compiler with /O2 option.
Details (expand)

Visual Studio/Silverlight/Tooling version

Visual Studio 2010

What category (if any) best represents this feedback?

 

Steps to reproduce

1) Write following C code
#include<stdio.h>

void func(char *p)
{
int i;
for ( i = 0; i<strlen(p);i++ )
         if ( p[i] == '/' )
             p[i] = '\\';
}
int main(void) {
    char *p = "testpath";
    func(p);
    return 0;
}


2) Compile it with following compiler options
cl /MD /O2 test.c

3) Compiler and Linker version
Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64
Microsoft (R) Incremental Linker Version 10.00.30319.01

4) Running on OS Windows 7 or Windows Server 2008 64 bit machine.

Product Language

 

Operating System

 

Operating System Language

 

Actual results

 

Expected results

 
File Attachments
File Name Submitted By Submitted On File Size  
newbottombanner.jpg (restricted) 8/18/2010 -
Sign in to post a comment.
Posted by Microsoft on 8/17/2010 at 5:41 PM
Hello. Thank you for your bug report. This is, indeed, an error in the generated code. This error will be fixed in a future release. In the meantime, please use the workaround suggested by jain_vipin_swim - passing a variable instead of a literal string should avoid the problem area.

Thank you.

Mark Levine
Dev Lead - Visual C++
Posted by Microsoft on 7/26/2010 at 1:44 AM
Thank you for reporting the issue.
We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution.These specialized experts will follow-up with your issue.
Posted by Microsoft on 7/24/2010 at 7:07 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Posted by ildjarn on 7/23/2010 at 8:01 AM
Verified in VC++ 2010 x64. Analysis of this issue has been discussed on the Visual C++ forums; see http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/0a200af3-98c8-4d06-b32b-804a6272070a
Sign in to post a workaround.
Posted by Vipin Jain on 7/23/2010 at 7:43 AM
Problem can be work-around by using following piece of code:

func(char *p ) {
int i;
for ( i =0 ; i<strlen(p); i++ )
         if ( p[i] == '/' )
             p[i] = '\\';
}
int main(void) {
char p[100];
strcpy(p,"string_literal");
func(p);
}