OJ's rants

It's not about you, it's about the software

WTF: Random Memory Contents

| Comments

If any of you out there are able to give me ONE GOOD REASON why anyone would do something like this, then please let me know. Below are “customised” realloc() and malloc() I recently stumbled across (yes, they get called. A LOT):

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
void *mcRealloc( void *P, int SIZE )
{
  int oldSize = _msize( P );

  P = realloc( P, SIZE );

  if ( P )
  {
    for ( int i = oldSize; i < SIZE; i++ )
    {
      ((char *) P)[i] = (char) rand();
    }
  }

  return P;
}

void *mcMalloc( int SIZE )
{
  void *P;

  P = malloc( SIZE );

  if ( P )
  {
    for ( int i = 0; i < SIZE; i++ )
    {
      ((char *) P)[i] = (char) rand();
    }
  }

  return P;
}

Is it just me, or is this a huge WTF?

Comments