summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2019-01-14 13:59:39 +0200
committerSergey Poznyakoff <gray@gnu.org>2019-01-14 13:59:39 +0200
commit3da8c2850d6589b9fa387ab2a2c87355d1224b1e (patch)
tree4a20822abc6aa37e6bf76fe834999dea88a2ccd2
parentc697d625982df4941ed51b6478256f9e7c7b8840 (diff)
downloadtar-3da8c2850d6589b9fa387ab2a2c87355d1224b1e.tar.gz
Fix iconv usage.
Patch by Christian Weisgerber. * src/utf8.c (utf8_convert): non-zero return from iconv means failure.
-rw-r--r--src/utf8.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/utf8.c b/src/utf8.c
index 95a016d4..91476aa9 100644
--- a/src/utf8.c
+++ b/src/utf8.c
@@ -81,7 +81,18 @@ utf8_convert (bool to_utf, char const *input, char **output)
outlen = inlen * MB_LEN_MAX + 1;
ob = ret = xmalloc (outlen);
ib = (char ICONV_CONST *) input;
- if (iconv (cd, &ib, &inlen, &ob, &outlen) == -1)
+ /* According to POSIX, "if iconv() encounters a character in the input
+ buffer that is valid, but for which an identical character does not
+ exist in the target codeset, iconv() shall perform an
+ implementation-defined conversion on this character." It will "update
+ the variables pointed to by the arguments to reflect the extent of the
+ conversion and return the number of non-identical conversions performed".
+ On error, it returns -1.
+ In other words, non-zero return always indicates failure, either because
+ the input was not fully converted, or because it was converted in a
+ non-reversible way.
+ */
+ if (iconv (cd, &ib, &inlen, &ob, &outlen) != 0)
{
free (ret);
return false;