Skip to content
Advertisement

strange output from g_print

I get the following error when I compile my code: file.h: In function ‘add_new_set’: file.h:7:53: warning: format not a string literal and no format arguments [-Wformat-security] g_print (gtk_entry_get_text ((GtkEntry *)((struct data *) callback_params)->entry));

here’s my code:

struct data
{
  GtkWidget * entry;
};
void add_new_set(GtkDialog *dialog, gint response_id, gpointer callback_params)
{
  g_print (gtk_entry_get_text ((GtkEntry *)((struct data *) callback_params)->entry));
}
static struct data callback_params;
    callback_params.entry = gtk_entry_new();
    gtk_container_add(GTK_CONTAINER(content_area), callback_params.entry);
    g_signal_connect(dialog,"response",G_CALLBACK (add_new_set),&callback_params);

now when I press the button to run the g_print part, If I type in ‘%s test’ I get: (null) test

now this seems like someething that can be maliciously used

any hints on what I’m facing here and what I should do?

thanks

Advertisement

Answer

Use a format specifier:

g_print (gtk_entry_get_text ((GtkEntry *)((struct data *) callback_params)->entry));

should be:

g_print ("%sn", gtk_entry_get_text ((GtkEntry *)((struct data *) callback_params)->entry));
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement