1

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 Answer 1

2

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:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.