summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-10-29 02:20:11 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-10-29 02:20:11 (EDT)
commit6cd51a3f9bfee94124e173bd81cde204f5ce75cf (patch)
treecd00e3136aaa91ae7335fd8713d6644a689070da
parent32314f1b0b8dad95601516614f33eb2375616f64 (diff)
downloadmarquee-6cd51a3f9bfee94124e173bd81cde204f5ce75cf.zip
marquee-6cd51a3f9bfee94124e173bd81cde204f5ce75cf.tar.gz
marquee-6cd51a3f9bfee94124e173bd81cde204f5ce75cf.tar.bz2
MqWebView: Fix segmentation faults on save name without "."
-rw-r--r--src/web-view.c17
1 files changed, 15 insertions, 2 deletions
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)) {