From e11fe86d73450d3f572e5b49ab0dc577ee9178b6 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Tue, 26 Aug 2008 06:21:10 +0000 Subject: Looks like I mis-remembered the API here. Also check for memory exhaustion. svn path=/trunk/netsurf/; revision=5207 --- utils/utf8.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'utils') diff --git a/utils/utf8.c b/utils/utf8.c index bce4f0e02..b8e3ca504 100644 --- a/utils/utf8.c +++ b/utils/utf8.c @@ -265,7 +265,7 @@ utf8_convert_ret utf8_from_enc(const char *string, const char *encname, * Convert a string from one encoding to another * * \param string The NULL-terminated string to convert - * \param len Length of input string to consider (in bytes) + * \param len Length of input string to consider (in bytes), or 0 * \param from The encoding name to convert from * \param to The encoding name to convert to * \param result Pointer to location in which to store result @@ -278,14 +278,20 @@ 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. */ + assert(string && from && to && result); + + if (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; + if (!(*result)) { + *result = NULL; + return UTF8_CONVERT_NOMEM; } - assert(string && from && to && result); + return UTF8_CONVERT_OK; + } if (strcasecmp(from, to) == 0) { /* conversion from an encoding to itself == strdup */ -- cgit v1.2.3