summaryrefslogtreecommitdiff
path: root/utils/utf8.c
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2008-08-26 00:53:02 +0000
committerChris Young <chris@unsatisfactorysoftware.co.uk>2008-08-26 00:53:02 +0000
commit553c4aac8bf369ae7b9a61e702279b7ef55eae44 (patch)
tree966d3f0b44f61349b79c437fe607987cbaca1f21 /utils/utf8.c
parentb89a093ba9203043a641ed870b02d55857e2f081 (diff)
downloadnetsurf-553c4aac8bf369ae7b9a61e702279b7ef55eae44.tar.gz
netsurf-553c4aac8bf369ae7b9a61e702279b7ef55eae44.tar.bz2
Prevent iconv() being passed an empty string in utf8_convert()
svn path=/trunk/netsurf/; revision=5202
Diffstat (limited to 'utils/utf8.c')
-rw-r--r--utils/utf8.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/utils/utf8.c b/utils/utf8.c
index 4c3c612f5..bce4f0e02 100644
--- a/utils/utf8.c
+++ b/utils/utf8.c
@@ -278,6 +278,13 @@ utf8_convert_ret utf8_convert(const char *string, size_t len,
char *temp, *out, *in;
size_t slen, rlen;
+ if (slen == 0 || string[0] == '\0') {
+ /* On AmigaOS, iconv() returns an error if we pass an empty string. This
+ * prevents iconv() being called as there is no conversion necessary anyway. */
+ *result = strdup("");
+ return UTF8_CONVERT_OK;
+ }
+
assert(string && from && to && result);
if (strcasecmp(from, to) == 0) {
@@ -333,6 +340,10 @@ utf8_convert_ret utf8_convert(const char *string, size_t len,
/* perform conversion */
if (iconv(cd, &in, &slen, &out, &rlen) == (size_t)-1) {
+
+ printf("Failed, errno == %d (%s)\n",
+ errno, strerror(errno));
+
free(temp);
/* clear the cached conversion descriptor as it's invalid */
last_cd.from[0] = '\0';