From 553c4aac8bf369ae7b9a61e702279b7ef55eae44 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Tue, 26 Aug 2008 00:53:02 +0000 Subject: Prevent iconv() being passed an empty string in utf8_convert() svn path=/trunk/netsurf/; revision=5202 --- utils/utf8.c | 11 +++++++++++ 1 file changed, 11 insertions(+) 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'; -- cgit v1.2.3