From 379145060b8fc90fa7c81c0bff20d025e61adc38 Mon Sep 17 00:00:00 2001 From: Gustavo Noronha Silva Date: Sun, 27 Dec 2009 23:43:06 -0200 Subject: Use GString instead of a plain string to hold content Yelp was holding the string that it gives WebKit for loading in a plain string, and ignoring the explicit length argument. In some cases the string was not correctly terminated by \0, and the document ended up with garbage. This was causing most of the XML parsing error messages that were being observed. This patch was made with help from Luciana Fujii . --- src/yelp-html.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/yelp-html.c b/src/yelp-html.c index bc07c37b..fae92748 100644 --- a/src/yelp-html.c +++ b/src/yelp-html.c @@ -38,7 +38,7 @@ #define YELP_HTML_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), YELP_TYPE_HTML, YelpHtmlPriv)) struct _YelpHtmlPriv { - gchar *content; + GString *content; gchar *mime; gchar *find_string; gboolean initialised; @@ -347,7 +347,8 @@ yelp_html_open_stream (YelpHtml *html, const gchar *mime) debug_print (DB_FUNCTION, "entering\n"); html->priv->frames_enabled = FALSE; - g_free (html->priv->content); + if (html->priv->content) + g_string_free (html->priv->content, TRUE); html->priv->content = NULL; g_free (html->priv->mime); html->priv->mime = g_strdup(mime); @@ -365,11 +366,9 @@ yelp_html_write (YelpHtml *html, const gchar *data, gint len) debug_print (DB_ARG, " len = %i\n", len); if (html->priv->content) { - tmp = g_strjoin (NULL, html->priv->content, data, NULL); - g_free (html->priv->content); - html->priv->content = tmp; + g_string_append_len (html->priv->content, data, len); } else { - html->priv->content = g_strdup (data); + html->priv->content = g_string_new_len (data, len); } } @@ -413,11 +412,11 @@ yelp_html_close (YelpHtml *html) } webkit_web_view_load_string (WEBKIT_WEB_VIEW (html), - html->priv->content, + html->priv->content->str, html->priv->mime, NULL, html->priv->base_uri); - g_free (html->priv->content); + g_string_free (html->priv->content, TRUE); html->priv->content = NULL; g_free (html->priv->mime); html->priv->mime = NULL; -- cgit v1.2.1