[Goodies-commits] r1855 - xfce4-clipman-plugin/trunk/panel-plugin
Nick Schermer
nick at xfce.org
Mon Aug 7 08:09:49 CEST 2006
Author: nick
Date: 2006-08-07 06:09:48 +0000 (Mon, 07 Aug 2006)
New Revision: 1855
Modified:
xfce4-clipman-plugin/trunk/panel-plugin/clipman.c
Log:
* Fix from Darren Salt
Modified: xfce4-clipman-plugin/trunk/panel-plugin/clipman.c
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/clipman.c 2006-08-06 22:01:47 UTC (rev 1854)
+++ xfce4-clipman-plugin/trunk/panel-plugin/clipman.c 2006-08-07 06:09:48 UTC (rev 1855)
@@ -117,23 +117,32 @@
{
gchar *s, *t, *u;
- s = g_strndup (txt, length*8);
+ s = g_strndup (txt, length*8 + 8);
+ if (!s)
+ {
+ DBG ("Eek, out of memory");
+ return NULL;
+ }
- if (!g_utf8_validate (s, -1, NULL))
+ if (!g_utf8_validate (s, -1, &t))
{
- DBG ("Title is not utf8 complaint, we're going to convert it");
-
+ /* Invalid char at/past length*8 & encoding is UTF-8? Get rid of it. */
+ if (t >= s + length * 8 && g_get_charset ((const gchar **)&u))
+ *t = 0;
+
+ DBG ("Title is not UTF-8 compliant, we're going to convert it");
+
u = g_locale_to_utf8 (s, -1, NULL, NULL, NULL);
- g_free (s);
- s = u;
-
- /* Check the title again */
- if (!g_utf8_validate (s, -1, NULL))
- {
- DBG ("Title is still not utf8 complaint, we going to drop this clip");
- g_free (s);
- return NULL;
- }
+ g_free (s);
+ s = u;
+
+ /* Check the title again */
+ if (!s || !g_utf8_validate (s, -1, NULL))
+ {
+ DBG ("Title is still not UTF-8 compliant, we're going to drop this clip");
+ g_free (s);
+ return NULL;
+ }
}
g_strstrip (s);
More information about the Goodies-commits
mailing list