Getting a “format not a string literal and no format arguments” warning while using GTK+2

1.4k views Asked by At

I am getting an error like this:

warning: format not a string literal and no format arguments [-Wformat-security]
                                              GTK_BUTTONS_OK,
(const gchar*)message);
                   ^

because of this function:

static void show_message (gchar *message, GtkMessageType type) {
  GtkWidget *dialog = gtk_message_dialog_new(NULL, 0, type,
                                             GTK_BUTTONS_OK,
                                             message);
  gtk_dialog_run(GTK_DIALOG(dialog));
  gtk_widget_destroy(dialog);
}

How can I fix it?

1

There are 1 answers

0
Mateusz Piotrowski On BEST ANSWER

The answer is quite simple.

You have to add "%s" to the arguments of the gtk_message_dialog_new() function like this:

static void show_message (gchar *message, GtkMessageType type) {
  GtkWidget *dialog = gtk_message_dialog_new(NULL, 0, type,
                                             GTK_BUTTONS_OK, "%s",
                                             message);
  gtk_dialog_run(GTK_DIALOG(dialog));
  gtk_widget_destroy(dialog);
}

Basically, the lack of "%s" is considered non-secure by gcc.

You can read more about it here: