From 6cd51a3f9bfee94124e173bd81cde204f5ce75cf Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sun, 29 Oct 2017 02:20:11 -0400 Subject: MqWebView: Fix segmentation faults on save name without "." --- diff --git a/src/web-view.c b/src/web-view.c index 84927fb..b2fc223 100644 --- a/src/web-view.c +++ b/src/web-view.c @@ -919,6 +919,19 @@ save_mhtml_cb(WebKitWebView *web_view, GAsyncResult *result) webkit_web_view_save_to_file_finish(web_view, result, NULL); } +static const gchar * +get_extension(const gchar *filename) +{ + const gchar *extension; + + extension = strrchr(filename, '.'); + if (extension) { + return extension + 1; + } else { + return filename + strlen(filename); + } +} + static gboolean extension_is_html(const gchar *extension) { @@ -992,7 +1005,7 @@ save_type_changed_cb(GtkComboBox *combo_box, GtkFileChooser *chooser) gchar *new_name; name = gtk_file_chooser_get_current_name(chooser); - extension = strrchr(name, '.') + 1; + extension = get_extension(name); active_id = gtk_combo_box_get_active_id(combo_box); if (g_strcmp0(active_id, "html") == 0) { @@ -1042,7 +1055,7 @@ save_response_cb(GtkWidget *dialog, gint response_id, MqWebView *web_view) active_id = gtk_combo_box_get_active_id( web_view->save_type_combo_box); if (g_strcmp0(active_id, "detect") == 0) { - extension = strrchr(filename, '.') + 1; + extension = get_extension(filename); if (extension_is_html(extension)) { save_html(web_view, file); } else if (extension_is_mhtml(extension)) { -- cgit v0.9.1