summaryrefslogtreecommitdiff
path: root/utils/utf8.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2008-08-26 06:21:10 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2008-08-26 06:21:10 +0000
commite11fe86d73450d3f572e5b49ab0dc577ee9178b6 (patch)
treee6ab8278aaf7c13a67978b4bdddedebe50030c0b /utils/utf8.c
parentc07794ed8d4a35330923337aa1134842bc7ee45b (diff)
downloadnetsurf-e11fe86d73450d3f572e5b49ab0dc577ee9178b6.tar.gz
netsurf-e11fe86d73450d3f572e5b49ab0dc577ee9178b6.tar.bz2
Looks like I mis-remembered the API here.
Also check for memory exhaustion. svn path=/trunk/netsurf/; revision=5207
Diffstat (limited to 'utils/utf8.c')
-rw-r--r--utils/utf8.c18
1 files changed, 12 insertions, 6 deletions
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 */