summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/String.cc11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/String.cc b/lib/String.cc
index 529a8dd..3d13efd 100644
--- a/lib/String.cc
+++ b/lib/String.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: String.cc,v 1.49 2008-01-25 10:09:19 pixel Exp $ */
+/* $Id: String.cc,v 1.50 2008-01-25 13:43:50 pixel Exp $ */
#include <stdio.h>
#include <string.h>
@@ -595,9 +595,14 @@ String & String::iconv(const String & from, const String & _to) {
::iconv (cd, &inbuf, &inleft, &outbuf, &outleft);
free(str);
+
+ siz = outbuf - t;
- str = (char *) malloc(outbuf - t + 1);
- memcpy(str, t, outbuf - t);
+ // let's pad up to 2 bytes in order to be safe with wchar_t's
+ str = (char *) malloc(siz + 2);
+ memcpy(str, t, siz);
+ str[siz] = 0;
+ str[siz + 1] = 0;
UNLOCK;
iconv_close(cd);