Commits

Anonymous committed 20bfeb2

g_convert() can return UTF-8 which doesn't pass g_utf8_validate(), very convenient

  • Participants
  • Parent commits 32e03e5
  • Branches gio

Comments (0)

Files changed (1)

File moo/mooedit/mooeditloader.c

     {
         gsize bytes_read;
         gsize bytes_written;
-        char *decoded = g_convert (data, data_len, "UTF-8", encoding,
-                                   &bytes_read, &bytes_written, NULL);
-        if (decoded)
+        char *decoded;
+
+        decoded = g_convert (data, data_len, "UTF-8", encoding,
+                             &bytes_read, &bytes_written, NULL);
+
+        if (decoded && strlen (decoded) == bytes_written)
         {
             loader->used_enc = g_strdup (encoding);
             loader->text = decoded;
         }
         else
         {
+            g_free (decoded);
             return FALSE;
         }
     }