Re: [gtk-list] Heisenberg was right?



> ** WARNING **: invalid unclassed pointer in cast to `GtkEntry'
> ** ERROR **: sigsegv caught

At first glance, looks like a corrupt pointer (i.e. the GtkWidget* variable
has had its value corrupted).

> This bug disappeared when I tried to see what happened, and added in 
> the function that made the bad call a simple
> printf("I'm here\n");
> The bug vanishes! (is this what is called a Heisenbug? Changes behavior
> when you try to observe it?)

Of all the types of bug that I've had to track down, the one that goes
away when you insert a print statement is the worst of all!

The reason the bug goes away is because, with the print statement in the
program, the string, "I'm here\n", goes into the program's data segment,
which results in the OTHER data structures in the data segment moving
to different addresses. Data corruption still happens, but the program 
just doesn't crash at the same place (if at all).

The most common reason for this behaviour, is using an uninitialised local
variable, usually either a pointer or a variable which is used to index an
array.

Other fairly common causes are: accidentally incrementing a pointer INSTEAD
OF an index you're using against it; buffer overflow; accidentally running
an array from 1 instead of from 0 (i.e. forgetting to normalise the index).

Now: the bad news :-(

There is a good (or bad?) chance that the piece of code which contains the
bug is nowhere near the code where the program crashes. What can happen is,
a corrupt pointer corrupts another pointer, which corrupts another pointer,
...... eventually, you use one of the corrupted pointers and crash.

Allan



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]