--- glib-2.14.0/glib/utf8.c
+++ glib-2.14.0-fixed/glib/utf8.c
@@ -1795,7 +1795,7 @@
   result = g_new (gchar, len + 1);
   r = result + len;
   p = str;
-  while (*p)
+  while (r>result)
     {
       skip = g_utf8_skip[*(guchar*)p];
       r -= skip;