Re: Strange behavior of my program

On Sun, 1 Dec 2013 21:01:48 +0100
Alberto Zichittella <a zichittella gmail com> wrote:
This message dialog causes a strange behavior on my program. It seems
that the call to gtk_message_dialog_new() change the value of the
const gchar* pointer, last parameter.

Furthermore, the value of the const gchar* variable "message" change
from "Il risultato e' -number-" to "Il risult(", I don't know why.
I know that the call changes the value (and the address) of message
because I use gdb.

I develope on ubuntu gnome 13.10 using Code::Blocks , on a 64bit
system, with gtk+-3.0

    const gchar* message;
    /*the function risolviFormat() create a gchar* pointer, using
malloc to allocate memory */
    message = espressione->risolviFormat();   //message is, for
example, "Il risultato e' 789"
    dialog = gtk_message_dialog_new (NULL,
   /*now message is "Il risult("
   gtk_dialog_run (GTK_DIALOG (dialog));
   gtk_widget_destroy (dialog);
   /*this call causes a segfault because message pointer changed his
value */

You probably have heap corruption somewhere, perhaps caused by double
freeing of the memory. Running your program under valgrind will tell you
what you are doing wrong if that is the case.  Otherwise something else
is modifying the memory pointed to by message (though that does not
explain the segfault).  If inspection of the code doesn't reveal the
mistake and you do not have heap corruption, you may need to use a


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