Access overrun

From Appmethod Topics
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
class someclass{
	int fnumber;
	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[])
	return 0;