sync with 0.8.9cvs4
[claws.git] / src / codeconv.c
index d12e5660878d97bce2ce62a500e7e75b000fb305..f6b3d41850c1b78e27d4509f54768bc8164a6da8 100644 (file)
@@ -785,13 +785,15 @@ gchar *conv_iconv_strdup(const gchar *inbuf,
        outbuf_p = outbuf;
        out_left = out_size;
 
-       while ((n_conv = iconv(cd, (gchar **)&inbuf_p, &in_left,
+       while ((n_conv = iconv(cd, (ICONV_CONST gchar **)&inbuf_p, &in_left,
                               &outbuf_p, &out_left)) < 0) {
                if (EILSEQ == errno) {
-                       *outbuf_p = '\0';
+                       g_free(outbuf);
+                       outbuf = NULL;
                        break;
                } else if (EINVAL == errno) {
-                       *outbuf_p = '\0';
+                       g_free(outbuf);
+                       outbuf = NULL;
                        break;
                } else if (E2BIG == errno) {
                        out_size *= 2;
@@ -808,6 +810,11 @@ gchar *conv_iconv_strdup(const gchar *inbuf,
                }
        }
 
+       if (outbuf) {
+               iconv(cd, NULL, NULL, &outbuf_p, &out_left);
+               outbuf = g_realloc(outbuf, strlen(outbuf) + 1);
+       }
+
        iconv_close(cd);
 
        return outbuf;