RSS
 

double-check your damn pointers, okay?

13 feb

Yesterday, working on my thesis, I felt like I died and resurrected more than once in a few hours. Trust me, I’m beginning to understand the way the compiler feels ;-)

Jokes apart, the following C++ code contains a bug similar to the one I found: can you spot it? (please forgive the bad indent )

void calledMethod( some_class *object )
{
arg = doSomething();
delete object;
object = new some_class( arg );
}

void callerMethod()
{
[...]
calledMethod( anObject );
anObject.doSomethingElse();
[...]
}

 
4 Comments

Posted in geek, me

 

Tags: , , , , ,

Leave a Reply

 

 
  1. nnoia

    19 febbraio 2008 at 10:38

    gh! facile :-P

     
    • kr1zz

      19 febbraio 2008 at 11:09

      mmm…per te ;-)

       
    • kr1zz

      19 febbraio 2008 at 11:20

      …ma ti dirò, la cosa pulp è che funzionava comunque!

       
  2. nnoia

    21 febbraio 2008 at 01:55

    funzionava comunque perchè lo usavi poco dopo e nel resto della app probabilmente hai una gestione locale della memoria, quindi la tua struttura era ancora lì, anche se pronta ad essere sovrascritta :-)