[gnome-documents/gnome-3-10] places-bookmarks: UTF-8 characters may take more than a single byte



commit 06aca2e63af33892dc71b05b00d94a791d212aa9
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Mar 6 15:08:21 2014 +0100

    places-bookmarks: UTF-8 characters may take more than a single byte
    
    The N in g_utf8_strncpy indicates the number of UTF-8 characters, not
    bytes. We can not operate on the assumption that one UTF-8 character
    will occupy a single byte.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=725822

 src/lib/gd-places-bookmarks.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
---
diff --git a/src/lib/gd-places-bookmarks.c b/src/lib/gd-places-bookmarks.c
index f235427..1a513d1 100644
--- a/src/lib/gd-places-bookmarks.c
+++ b/src/lib/gd-places-bookmarks.c
@@ -177,8 +177,8 @@ static char *
 get_pretty_name (const char *text)
 {
         char *name = NULL;
-        char trimmed[MAX_LEN_LABEL];
-        char basename[MAX_LEN_LABEL];
+        char *trimmed;
+        char *basename;
         int i;
         int last_word = -1;
         int last_sentence = -1;
@@ -189,7 +189,7 @@ get_pretty_name (const char *text)
 
         num_attrs = MIN (g_utf8_strlen (text, -1) + 1, MAX_LEN_LABEL);
         attrs = g_new (PangoLogAttr, num_attrs);
-        g_utf8_strncpy (trimmed, text, num_attrs - 1);
+        trimmed = g_utf8_substring (text, 0, num_attrs - 1);
         pango_get_log_attrs (trimmed, -1, -1, pango_language_get_default (), attrs, num_attrs);
 
         /* since the end of the text will always match a word boundary don't include it */
@@ -213,13 +213,16 @@ get_pretty_name (const char *text)
                 i = last_word;
         }
 
-        g_utf8_strncpy (basename, trimmed, i);
+        basename = g_utf8_substring (trimmed, 0, i);
         if (ellipse) {
                 name = g_strdup_printf ("“%s…”", basename);
         } else {
                 name = g_strdup_printf ("“%s”", basename);
         }
 
+        g_free (basename);
+        g_free (trimmed);
+
         return name;
 }
 


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