1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
//----------------------------------------------------------------------------
//Borland C++Builder
//Copyright (c) 2000-2002 Borland Corporation. All Rights Reserved.
//----------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
USERES("buggy.res");
//---------------------------------------------------------------------------
/***************************************************************************\
WARNING : This program contains intentional memory allocation errors, and
other programming errors. It is intended to demonstrate how CodeGuard will
detect programming errors. You should ensure that you have shut down any
other applications that may be running and that you have saved all your files
before running this application.
\***************************************************************************/
class MyClass {
private:
int x;
public:
void SetX(int xx) {x = xx;}
};
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
//double free
void *p = malloc(123);
free(p);
free(p);
//access after free
int *i = (int*)malloc(sizeof(int));
free(i);
*i = 99;
//allocated with new[] deallocated with delete (no brackets)
char *c = new char[64];
delete c;
//overrun the end of the array
char foo[10];
foo[11] = 'a'; |
Partager