[geany/geany-plugins] ce22ed: markdown: Fix possible crasher

Matthew Brush git-noreply at xxxxx
Sun Aug 26 09:16:28 UTC 2012


Branch:      refs/heads/master
Author:      Matthew Brush <matt at geany.org>
Committer:   Matthew Brush <matt at geany.org>
Date:        Tue, 17 Jul 2012 04:24:22
Commit:      ce22ed9fca631bed99aaf281372cc63d3a2b73f3
             https://github.com/geany/geany-plugins/commit/ce22ed9fca631bed99aaf281372cc63d3a2b73f3

Log Message:
-----------
markdown: Fix possible crasher

Always ensure that the viewer's internal GString buffer is created
just to be safe. Also ensure the viewer is always updated which will
make sure the internal buffer is always created anyway.


Modified Paths:
--------------
    markdown/src/plugin.c
    markdown/src/viewer.c

Modified: markdown/src/plugin.c
15 files changed, 11 insertions(+), 4 deletions(-)
===================================================================
@@ -62,10 +62,12 @@
 /* Main plugin entry point on plugin load. */
 void plugin_init(GeanyData *data)
 {
+  gint page_num;
   gchar *conf_fn;
   MarkdownConfig *conf;
   MarkdownConfigViewPos view_pos;
   GtkWidget *viewer;
+  GtkNotebook *nb;
 
   /* Setup the config object which is needed by the view. */
   conf_fn = g_build_filename(geany->app->configdir, "plugins", "markdown",
@@ -84,16 +86,17 @@ void plugin_init(GeanyData *data)
     GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
 
   if (view_pos == MARKDOWN_CONFIG_VIEW_POS_MSGWIN) {
-    gtk_notebook_append_page(
-      GTK_NOTEBOOK(geany->main_widgets->message_window_notebook),
+    nb = GTK_NOTEBOOK(geany->main_widgets->message_window_notebook);
+    page_num = gtk_notebook_append_page(nb,
       g_scrolled_win, gtk_label_new(MARKDOWN_PREVIEW_LABEL));
   } else {
-    gtk_notebook_append_page(
-      GTK_NOTEBOOK(geany->main_widgets->sidebar_notebook),
+    nb = GTK_NOTEBOOK(geany->main_widgets->sidebar_notebook);
+    page_num = gtk_notebook_append_page(nb,
       g_scrolled_win, gtk_label_new(MARKDOWN_PREVIEW_LABEL));
   }
 
   gtk_widget_show_all(g_scrolled_win);
+  gtk_notebook_set_current_page(nb, page_num);
 
   g_signal_connect(conf, "notify::view-pos", G_CALLBACK(on_view_pos_notify), viewer);
 
@@ -112,6 +115,8 @@ void plugin_init(GeanyData *data)
   /* Prevent segfault in plugin when it registers GTypes and gets unloaded
    * and when reloaded tries to re-register the GTypes. */
   plugin_module_make_resident(geany_plugin);
+
+  update_markdown_viewer(MARKDOWN_VIEWER(viewer));
 }
 
 /* Cleanup resources on plugin unload. */
@@ -225,4 +230,6 @@ static void on_document_filetype_set(GObject *obj, GeanyDocument *doc, GeanyFile
   gtk_notebook_set_current_page(newnb, page_num);
 
   g_object_unref(g_scrolled_win); /* The new notebook owns it now */
+
+  update_markdown_viewer(viewer);
 }


Modified: markdown/src/viewer.c
7 files changed, 7 insertions(+), 0 deletions(-)
===================================================================
@@ -299,11 +299,18 @@ struct _MarkdownViewerPrivate
 markdown_viewer_get_html(MarkdownViewer *self)
 {
   gchar *md_as_html, *html = NULL;
+
+  /* Ensure the internal buffer is created */
+  if (!self->priv->text) {
+    update_internal_text(self, "");
+  }
+
   md_as_html = mkd_compile_document(self->priv->text->str, 0);
   if (md_as_html) {
     html = template_replace(self, md_as_html);
     g_free(md_as_html);
   }
+
   return html;
 }
 


@@ Diff output truncated at 100000 characters. @@


--------------
This E-Mail was brought to you by github_commit_mail.py (Source: TBD).



More information about the Plugins-Commits mailing list