changeset 642:ebbe3845b46b

Fix a crash when a resource contains non-representable chars
author Mikael Berthe <mikael@lilotux.net>
date Fri, 30 Dec 2005 12:46:48 +0100
parents 62679532ea55
children dd73c3dad815
files mcabber/src/jabglue.c
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/jabglue.c	Wed Dec 28 19:05:11 2005 +0100
+++ b/mcabber/src/jabglue.c	Fri Dec 30 12:46:48 2005 +0100
@@ -1394,14 +1394,20 @@
     if (m++) {
       s = from_utf8(m);
       if (s) {
-        // The length should be enough because from_utf should only
-        // reduce the string length
+        // In some cases the allocated memory size could be too small because
+        // when chars cannot be converted strings like "\uxxxx" or "\Uxxxxyyyy"
+        // are used.
+        if (strlen(r+1) < strlen(s)) {
+          from = g_realloc(from, 1+m-p+strlen(s));
+          r = strchr(from, '/');
+        }
         strcpy(r+1, s);
         g_free(s);
       } else {
         *(r+1) = 0;
         scr_LogPrint(LPRINT_NORMAL, "Decoding of message sender has failed");
-        scr_LogPrint(LPRINT_LOG, "Decoding of message sender has failed: %s", m);
+        scr_LogPrint(LPRINT_LOG, "Decoding of message sender has failed: %s",
+                     m);
       }
     }
   }