Permalink
Browse files

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.
  • Loading branch information...
1 parent 2ddd10f commit ce22ed9fca631bed99aaf281372cc63d3a2b73f3 @codebrainz committed Jul 17, 2012
Showing with 18 additions and 4 deletions.
  1. +11 −4 markdown/src/plugin.c
  2. +7 −0 markdown/src/viewer.c
View
@@ -62,10 +62,12 @@ static void on_view_pos_notify(GObject *obj, GParamSpec *pspec, MarkdownViewer *
/* 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 @@ on_view_pos_notify(GObject *obj, GParamSpec *pspec, MarkdownViewer *viewer)
gtk_notebook_set_current_page(newnb, page_num);
g_object_unref(g_scrolled_win); /* The new notebook owns it now */
+
+ update_markdown_viewer(viewer);
}
View
@@ -299,11 +299,18 @@ static gchar *
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;
}

0 comments on commit ce22ed9

Please sign in to comment.