File: cccc_new.cc

package info (click to toggle)
cccc 3.pre81-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,820 kB
  • ctags: 4,972
  • sloc: ansic: 33,244; cpp: 10,691; java: 618; makefile: 165; sh: 11
file content (73 lines) | stat: -rw-r--r-- 1,173 bytes parent folder | download | duplicates (2)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// cccc_new.cc

// we are having some problems with heap corruption, so I am making sure that
// all class news and deletes are done by the malloc subsystem, and adding 
// logging and deletion suppression

#include "cccc.h"

#include <stdlib.h>
#include <memory.h>
#ifdef CCCC_CONF_W32VC
#include <time.h>
#else
#ifdef CCCC_CONF_W32BC
#include <time.h>
#else
#include <sys/time.h>
#endif
#endif

#define USE_SYSTEM_NEW
#ifndef USE_SYSTEM_NEW
extern int dont_free;

ofstream str("cccc_new.log");

void *
operator new(size_t n) 
{
  void *retval=malloc(n);
  memset(retval,0xFA,n);
  str << hex << retval << "@" << time(NULL) << "+" << n << endl;
  return retval;
}

void *
operator new[](size_t n)
{
  void *retval=malloc(n);
  memset(retval,0xFB,n);
  str << hex << retval << "@" << time(NULL) << "*" << n << endl;
  return retval;
}

void
operator delete(void * cp)
{
  str << hex << cp << "@" << time(NULL) << "-" << endl;
  memset(cp,0xFC,1);
  if(dont_free==0)
    {
      free(cp);
    }
}

void
operator delete[](void * cp)
{
  str << hex << cp << "@" << time(NULL) << "/" << endl;
  memset(cp,0xFD,1);
  if(dont_free==0)
    {
      free(cp);
    }
}


#endif