From: John Darrington <john@darrington.wattle.id.au> Date: Wed, 7 Jun 2017 12:15:15 +0000 (+0200) Subject: PsppireDelimitedText (count_delims): Make the iteration multibyte character safe X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d7fc81f8029f7503ff07ea3cbd78b6313c46e4c3;p=pspp PsppireDelimitedText (count_delims): Make the iteration multibyte character safe --- diff --git a/src/ui/gui/psppire-delimited-text.c b/src/ui/gui/psppire-delimited-text.c index b02a0ac9ea..a63ccc25dc 100644 --- a/src/ui/gui/psppire-delimited-text.c +++ b/src/ui/gui/psppire-delimited-text.c @@ -63,14 +63,16 @@ count_delims (PsppireDelimitedText *tf) { gint enc = -1; // FIXME: Box these lines to avoid constant allocation/deallocation - gchar *foo = 0; - gtk_tree_model_get (tf->child, &iter, 1, &foo, -1); + gchar *line = NULL; + gtk_tree_model_get (tf->child, &iter, 1, &line, -1); { - char *line = foo; + char *p; gint count = 0; - while (*line) + for (p = line; ; p = g_utf8_find_next_char (p, NULL)) { - const gunichar c = *line; //FIXME: Not multibyte safe! + const gunichar c = g_utf8_get_char (p); + if (c == NULL) + break; if (enc == -1) { gint i; @@ -96,11 +98,10 @@ count_delims (PsppireDelimitedText *tf) count++; } } - line++; } tf->max_delimiters = MAX (tf->max_delimiters, count); } - g_free (foo); + g_free (line); } }