Access overrun

From RAD Studio
Jump to: navigation, search

Go Up to Access Errors


An Access Overrun error occurs because of accessing memory after the end of a region of memory, such as indexing the third array item in a list of two items or copying data past the end of a region of memory. Both of these are present in the following code:

#include <tchar.h>
#pragma hdrstop
#include<stdio.h>
#include<dir.h>
class someclass{
	int fnumber;
  public:
	int getnumber(){return fnumber;}
	void setnumber(int nw){fnumber = nw;}
	int doublev(int val){return val*2;}
	int publicalval;

};

void myf()
{
  someclass *myc = new someclass[2];
  int answ;
  answ = myc[2].publicalval = 10; //error
  delete[] myc;
  char *chlist = new char[10];
  strcpy(chlist, "1234567890" )  ; // error
  delete [] chlist;
 
}



int _tmain(int argc, _TCHAR* argv[])
{
	myf();
	return 0;
}