Skip to content
Prev 51580 / 63421 Next

iconv to UTF-16 encoding produces error due to embedded nulls (write.table with fileEncoding param)

On 23.02.2016 11:37, Martin Maechler wrote:
I took a look at connections.c. There is a call to strlen() that gets
confused by null characters. I think the obvious fix is to avoid the
call to strlen() as the size is already known:

Index: src/main/connections.c
===================================================================
--- src/main/connections.c	(revision 70213)
+++ src/main/connections.c	(working copy)
@@ -369,7 +369,7 @@
 		/* is this safe? */
 		warning(_("invalid char string in output conversion"));
 	    *ob = '\0';
-	    con->write(outbuf, 1, strlen(outbuf), con);
+	    con->write(outbuf, 1, ob - outbuf, con);
 	} while(again && inb > 0);  /* it seems some iconv signal -1 on
 				       zero-length input */
     } else
With the patch applied:

    > readLines(fn, encoding="UTF-16LE", skipNul=TRUE)
    [1] "C"  "B"  "A"  "|"  ">a"
    > file.size(fn)
    [1] 22

- Mikko Korpela

Thread (15 messages)

nospam at altfeld-im.de iconv to UTF-16 encoding produces error due to embedded nulls (write.table with fileEncoding param) Feb 16 nospam at altfeld-im.de iconv to UTF-16 encoding produces error due to embedded nulls (write.table with fileEncoding param) Feb 22 Martin Maechler iconv to UTF-16 encoding produces error due to embedded nulls (write.table with fileEncoding param) Feb 23 Mikko Korpela iconv to UTF-16 encoding produces error due to embedded nulls (write.table with fileEncoding param) Feb 23 nospam at altfeld-im.de iconv to UTF-16 encoding produces error due to embedded nulls (write.table with fileEncoding param) Feb 23 Duncan Murdoch iconv to UTF-16 encoding produces error due to embedded nulls (write.table with fileEncoding param) Feb 23 Duncan Murdoch iconv to UTF-16 encoding produces error due to embedded nulls (write.table with fileEncoding param) Feb 24 Mikko Korpela iconv to UTF-16 encoding produces error due to embedded nulls (write.table with fileEncoding param) Feb 24 Duncan Murdoch iconv to UTF-16 encoding produces error due to embedded nulls (write.table with fileEncoding param) Feb 24 Duncan Murdoch iconv to UTF-16 encoding produces error due to embedded nulls (write.table with fileEncoding param) Feb 24 Mikko Korpela iconv to UTF-16 encoding produces error due to embedded nulls (write.table with fileEncoding param) Feb 25 Peter Dalgaard iconv to UTF-16 encoding produces error due to embedded nulls (write.table with fileEncoding param) Feb 25 Mikko Korpela iconv to UTF-16 encoding produces error due to embedded nulls (write.table with fileEncoding param) Feb 25 Duncan Murdoch iconv to UTF-16 encoding produces error due to embedded nulls (write.table with fileEncoding param) Feb 29 Mikko Korpela iconv to UTF-16 encoding produces error due to embedded nulls (write.table with fileEncoding param) Feb 29