Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Thu, 16 Nov 2023 09:56:02 UTC Commit: 496519d6631dfdef8d41559c642deac933e22f97 https://github.com/geany/geany/commit/496519d6631dfdef8d41559c642deac933e22f...
Log Message: ----------- Only pass literals as format strings for e.g. printf-style functions
Passing a non-literal prevents the compiler from checking the arguments match the format, potentially hiding otherwise easy to detect bugs.
Modified Paths: -------------- src/document.c src/libmain.c src/search.c
Modified: src/document.c 15 lines changed, 9 insertions(+), 6 deletions(-) =================================================================== @@ -1017,15 +1017,18 @@ static gboolean load_text_file(const gchar *locale_filename, const gchar *displa
if (filedata->readonly) { - const gchar *warn_msg = _( - "The file "%s" could not be opened properly and has been truncated. " \ - "This can occur if the file contains a NULL byte. " \ - "Be aware that saving it can cause data loss.\nThe file was set to read-only."); + gchar *warn_msg = g_strdup_printf(_( + "The file "%s" could not be opened properly and has been truncated. " + "This can occur if the file contains a NULL byte. " + "Be aware that saving it can cause data loss.\nThe file was set to read-only."), + display_filename);
if (main_status.main_window_realized) - dialogs_show_msgbox(GTK_MESSAGE_WARNING, warn_msg, display_filename); + dialogs_show_msgbox(GTK_MESSAGE_WARNING, "%s", warn_msg); + + ui_set_statusbar(TRUE, "%s", warn_msg);
- ui_set_statusbar(TRUE, warn_msg, display_filename); + g_free(warn_msg); }
return TRUE;
Modified: src/libmain.c 16 lines changed, 9 insertions(+), 7 deletions(-) =================================================================== @@ -882,11 +882,11 @@ static void open_cl_files(gint argc, gchar **argv) #endif if (filename && ! main_handle_filename(filename)) { - const gchar *msg = _("Could not find file '%s'."); + gchar *msg = g_strdup_printf(_("Could not find file '%s'."), filename);
- g_printerr(msg, filename); /* also print to the terminal */ - g_printerr("\n"); - ui_set_statusbar(TRUE, msg, filename); + g_printerr("%s\n", msg); /* also print to the terminal */ + ui_set_statusbar(TRUE, "%s", msg); + g_free(msg); } g_free(filename); } @@ -1174,9 +1174,11 @@ gint main_lib(gint argc, gchar **argv) ui_set_statusbar(TRUE, _("This is Geany %s."), main_get_version_string()); if (config_dir_result != 0) { - const gchar *message = _("Configuration directory could not be created (%s)."); - ui_set_statusbar(TRUE, message, g_strerror(config_dir_result)); - g_warning(message, g_strerror(config_dir_result)); + gchar *message = g_strdup_printf(_("Configuration directory could not be created (%s)."), + g_strerror(config_dir_result)); + ui_set_statusbar(TRUE, "%s", message); + g_warning("%s", message); + g_free(message); } #ifdef HAVE_SOCKET if (socket_info.lock_socket == -1)
Modified: src/search.c 10 lines changed, 6 insertions(+), 4 deletions(-) =================================================================== @@ -1883,12 +1883,14 @@ static void search_finished(GPid child_pid, gint status, gpointer user_data) { gint count = gtk_tree_model_iter_n_children( GTK_TREE_MODEL(msgwindow.store_msg), NULL) - 1; - gchar *text = ngettext( + gchar *text = g_strdup_printf(ngettext( "Search completed with %d match.", - "Search completed with %d matches.", count); + "Search completed with %d matches.", count), + count);
- msgwin_msg_add(COLOR_BLUE, -1, NULL, text, count); - ui_set_statusbar(FALSE, text, count); + msgwin_msg_add_string(COLOR_BLUE, -1, NULL, text); + ui_set_statusbar(FALSE, "%s", text); + g_free(text); break; } case 1:
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).