Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

heap corruption

Name: Anonymous 2009-06-18 3:05

would this cause heap corruption?

int main()
{
   char *s = new char[4];
   delete &s[0];
   delete [] s;
   return 0;
}

Name: Anonymous 2009-06-18 3:30

No, although the behavior of deleting something that is already deleted is implementation defined.

Name: Anonymous 2009-06-18 4:36

Now if you did a

int main()
{
   char *s = new char[4];
   memcpy(s,"deadbeef",sizeof(char) * 8);
   delete s;
   return 0;
}

You'd get something a bit more fun (probably a write AV)

int main()
{
   char *s = new char[4];
   char *t = new char[10];
   memcpy(s,"deadbeef",sizeof(char) * 8);
   delete s;
   return 0;
}

This'll probably give you some heap corruption.

Name: Anonymous 2009-06-18 5:47

sepplesgayness

Name: Anonymous 2009-06-18 8:53

>>3
sizeof(char)
Read the Stadard, moran.

Name: Anonymous 2009-06-18 9:03

>>5
(sizeof you're momma)
*** Exception: Stack Overflow

Name: Anonymous 2009-06-18 9:17

>>6
(sizeof you're momma)
Your overdoing it. Everybody knows that this is a nigger thing to say, especially using words like "momma", but no nigger can ever learn Lisp.

FAIL FIAL FAIL LRN2TROL FAIL

Name: Anonymous 2009-06-18 9:33

>>7
LOL I TROL YOU LOLOLOLOLOLOLOLOLOLOLOLOL

Name: Anonymous 2009-06-18 9:33

>>7
Also that's Haskell, not LISP.

Name: Anonymous 2009-06-18 18:15

>>1
   char *s = new char[4];
   delete &s[0];

or the equivalent
char *s = new char[4];
   delete s;

will indeed corrupt the heap as side effect of performing the delete.  It just won't show until you do something else interesting with the heap.

Name: Anonymous 2009-06-18 20:15

Name: Anonymous 2011-02-04 17:06

Name: Anonymous 2011-02-04 17:57

<

Don't change these.
Name: Email:
Entire Thread Thread List