[gtksourceview/wip/uchardet: 2/2] guess_encoding_fallback() return the last encoding even if it fails.



commit 82d3d5c2c2f91a8000e5d5c89f686f8efd2cee40
Author: Jehan <jehan girinstud io>
Date:   Sat Sep 5 16:28:27 2015 +0200

    guess_encoding_fallback() return the last encoding even if it fails.
    
    If all try_convert() tests fails, we should return NULL, not the last
    encoding we tried.

 gtksourceview/gtksourcebufferoutputstream.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
---
diff --git a/gtksourceview/gtksourcebufferoutputstream.c b/gtksourceview/gtksourcebufferoutputstream.c
index 18b6e51..d30c612 100644
--- a/gtksourceview/gtksourcebufferoutputstream.c
+++ b/gtksourceview/gtksourcebufferoutputstream.c
@@ -390,6 +390,7 @@ guess_encoding_fallback (GtkSourceBufferOutputStream *stream,
                         gsize                        inbuf_size)
 {
        GCharsetConverter *conv = NULL;
+       gboolean success = FALSE;
 
        if (stream->priv->encodings != NULL &&
            stream->priv->encodings->next == NULL)
@@ -454,6 +455,7 @@ guess_encoding_fallback (GtkSourceBufferOutputStream *stream,
                /* Try to convert */
                if (try_convert (conv, inbuf, inbuf_size))
                {
+                       success = TRUE;
                        break;
                }
        }
@@ -462,6 +464,10 @@ guess_encoding_fallback (GtkSourceBufferOutputStream *stream,
        {
                g_converter_reset (G_CONVERTER (conv));
        }
+       if (!success)
+       {
+               g_clear_object (&conv);
+       }
 
        return conv;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]