diff --git a/modules/basic/basic-win32.c b/modules/basic/basic-win32.c
index 2483022..e69205c 100644
--- a/modules/basic/basic-win32.c
+++ b/modules/basic/basic-win32.c
@@ -423,7 +423,7 @@ convert_log_clusters_to_byte_offsets (const char       *text,
   const char *p;
   int charix, glyphix;
   int n_chars = g_utf8_strlen (text, length);
-  int *byte_offset = g_new (int, n_chars);
+  int *byte_offset = g_new (int, n_chars * 2);
 
   p = text;
   charix = 0;
@@ -431,14 +431,18 @@ convert_log_clusters_to_byte_offsets (const char       *text,
     {
       byte_offset[charix] = p - text;
       charix++;
+      if (g_utf8_get_char (p) > 0xFFFF)
+      {
+	byte_offset[charix] = p - text;
+	charix++;
+      }
       p = g_utf8_next_char (p);
     }
 
-  /* Convert char indexes in the log_clusters array to byte offsets.
-   */
+  /* Convert utf16 indexes in the log_clusters array to byte offsets. */
   for (glyphix = 0; glyphix < glyphs->num_glyphs; glyphix++)
     {
-      g_assert (glyphs->log_clusters[glyphix] < n_chars);
+      g_assert (glyphs->log_clusters[glyphix] < charix);
       glyphs->log_clusters[glyphix] = byte_offset[glyphs->log_clusters[glyphix]];
     }
 
