By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,218 Members | 1,111 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,218 IT Pros & Developers. It's quick & easy.

Memory access violations and Managed C++

P: n/a
In the attached code fragment I have a buffer overflow and
a memory access violation. When I run the code .Net fails to
verify the IL because of the buffer overflow and I get an exception
as expected. My question relates to the memory access violation,
specfically, what should happen? My guess is that since the good
ole new operator allocates the memory we get an SEH memory access
violation exception. Given that this can occur in my managed
code fragment, what assurances do I have when running such code?
I had thought that managed code prevented this kind of access
violation.

Thanks for your help, and sorry for the dumb question, I'm a little
late to the party.

// This is the main project file for VC++ application project
// generated using an Application Wizard.

#include "stdafx.h"

#using <mscorlib.dll>
#include <tchar.h>

using namespace System;

// This is the entry point for this application
int _tmain(void)
{
// TODO: Please replace the sample code below with your own.
int* pInt=new int;

// bad boy
pInt[0xA]=0x999;

int Buffer[0xA];
Buffer[0xAA]=0xDDDD;

//String* pTempStr=new String("Hello world");
//Console::WriteLine(pTempStr);
return 0;
}
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Verifiable managed code does. Your example does not.

Ronald Laeremans
Visual C++ team

"BillyO" <Bi********@cali.com> wrote in message
news:9l********************************@4ax.com...
In the attached code fragment I have a buffer overflow and
a memory access violation. When I run the code .Net fails to
verify the IL because of the buffer overflow and I get an exception
as expected. My question relates to the memory access violation,
specfically, what should happen? My guess is that since the good
ole new operator allocates the memory we get an SEH memory access
violation exception. Given that this can occur in my managed
code fragment, what assurances do I have when running such code?
I had thought that managed code prevented this kind of access
violation.

Thanks for your help, and sorry for the dumb question, I'm a little
late to the party.

// This is the main project file for VC++ application project
// generated using an Application Wizard.

#include "stdafx.h"

#using <mscorlib.dll>
#include <tchar.h>

using namespace System;

// This is the entry point for this application
int _tmain(void)
{
// TODO: Please replace the sample code below with your own.
int* pInt=new int;

// bad boy
pInt[0xA]=0x999;

int Buffer[0xA];
Buffer[0xAA]=0xDDDD;

//String* pTempStr=new String("Hello world");
//Console::WriteLine(pTempStr);
return 0;
}

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.