Re: Strange behavior of my program
- From: Tristan Van Berkom <tristan upstairslabs com>
- To: onetmt <onetmt gmail com>
- Cc: gtk-list gnome org
- Subject: Re: Strange behavior of my program
- Date: Tue, 10 Dec 2013 14:42:01 +0900
On Tue, 2013-12-10 at 06:31 +0100, onetmt wrote:
Il 01/12/2013 21:01, Alberto Zichittella ha scritto:
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,
Try this substitution:
gchar *message;
message = g_strdup_printf("Il risultato e': %f", result);
dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
(const gchar *)message);
You really should not be passing a literal string as a format.
What you really want is:
dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"Il risultato e': %f",
result);
"Il risultato e' 789"
dialog = gtk_message_dialog_new (NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
message);
/*now message is "Il risult("
gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER_ALWAYS);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
/*this call causes a segfault because message pointer changed his
value */
free(message);
This causes a segfault cause you're freeing glib memory with
libc 'free()'
return;
--
Mio blog: http://newbufferedwriter.blogspot.com/
http://prodigious.altervista.org/Scrobblit/index.php
_______________________________________________
gtk-list mailing list
gtk-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]