diff options
author | Vincent Sanders <vince@netsurf-browser.org> | 2013-10-25 20:58:19 +0100 |
---|---|---|
committer | Vincent Sanders <vince@netsurf-browser.org> | 2013-10-25 21:25:56 +0100 |
commit | f29306cc9aae8365ab52418c589700c0f448fbd4 (patch) | |
tree | f596c4974de03683c9f75c381c475fbdb62da308 /utils | |
parent | 1d326a8a1c83f5dd7e1390d1b806138981f56574 (diff) | |
download | netsurf-f29306cc9aae8365ab52418c589700c0f448fbd4.tar.gz netsurf-f29306cc9aae8365ab52418c589700c0f448fbd4.tar.bz2 |
improve gtk source save to use gtk overwrite protection feature coverity 1109873
Diffstat (limited to 'utils')
-rw-r--r-- | utils/utf8.c | 74 | ||||
-rw-r--r-- | utils/utf8.h | 2 |
2 files changed, 40 insertions, 36 deletions
diff --git a/utils/utf8.c b/utils/utf8.c index 127ffe642..8e9587d20 100644 --- a/utils/utf8.c +++ b/utils/utf8.c @@ -33,9 +33,6 @@ #include "utils/log.h" #include "utils/utf8.h" -static utf8_convert_ret utf8_convert(const char *string, size_t len, - const char *from, const char *to, char **result); - /** * Convert a UTF-8 multibyte sequence into a single UCS4 character * @@ -217,35 +214,6 @@ void utf8_finalise(void) utf8_clear_cd_cache(); } -/** - * Convert a UTF8 string into the named encoding - * - * \param string The NULL-terminated string to convert - * \param encname The encoding name (suitable for passing to iconv) - * \param len Length of input string to consider (in bytes), or 0 - * \param result Pointer to location to store result (allocated on heap) - * \return Appropriate utf8_convert_ret value - */ -utf8_convert_ret utf8_to_enc(const char *string, const char *encname, - size_t len, char **result) -{ - return utf8_convert(string, len, "UTF-8", encname, result); -} - -/** - * Convert a string in the named encoding into a UTF-8 string - * - * \param string The NULL-terminated string to convert - * \param encname The encoding name (suitable for passing to iconv) - * \param len Length of input string to consider (in bytes), or 0 - * \param result Pointer to location to store result (allocated on heap) - * \return Appropriate utf8_convert_ret value - */ -utf8_convert_ret utf8_from_enc(const char *string, const char *encname, - size_t len, char **result) -{ - return utf8_convert(string, len, encname, "UTF-8", result); -} /** * Convert a string from one encoding to another @@ -254,11 +222,13 @@ utf8_convert_ret utf8_from_enc(const char *string, const char *encname, * \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 + * \param result Pointer to location in which to store result. + * \param result_len Pointer to location in which to store result length. * \return Appropriate utf8_convert_ret value */ -utf8_convert_ret utf8_convert(const char *string, size_t len, - const char *from, const char *to, char **result) +static utf8_convert_ret utf8_convert(const char *string, size_t len, + const char *from, const char *to, + char **result, size_t *result_len) { iconv_t cd; char *temp, *out, *in; @@ -356,9 +326,43 @@ utf8_convert_ret utf8_convert(const char *string, size_t len, * converted to UTF-32 */ memset((*result) + (out - temp), 0, 4); + if (result_len != NULL) { + *result_len = (out - temp); + } + return UTF8_CONVERT_OK; } +/** + * Convert a UTF8 string into the named encoding + * + * \param string The NULL-terminated string to convert + * \param encname The encoding name (suitable for passing to iconv) + * \param len Length of input string to consider (in bytes), or 0 + * \param result Pointer to location to store result (allocated on heap) + * \return Appropriate utf8_convert_ret value + */ +utf8_convert_ret utf8_to_enc(const char *string, const char *encname, + size_t len, char **result) +{ + return utf8_convert(string, len, "UTF-8", encname, result, NULL); +} + +/** + * Convert a string in the named encoding into a UTF-8 string + * + * \param string The NULL-terminated string to convert + * \param encname The encoding name (suitable for passing to iconv) + * \param len Length of input string to consider (in bytes), or 0 + * \param result Pointer to location to store result (allocated on heap) + * \return Appropriate utf8_convert_ret value + */ +utf8_convert_ret utf8_from_enc(const char *string, const char *encname, + size_t len, char **result, size_t *result_len) +{ + return utf8_convert(string, len, encname, "UTF-8", result, result_len); +} + static utf8_convert_ret utf8_convert_html_chunk(iconv_t cd, const char *chunk, size_t inlen, char **out, size_t *outlen) diff --git a/utils/utf8.h b/utils/utf8.h index eb043c227..68d42d3ea 100644 --- a/utils/utf8.h +++ b/utils/utf8.h @@ -47,7 +47,7 @@ size_t utf8_next(const char *s, size_t l, size_t o); utf8_convert_ret utf8_to_enc(const char *string, const char *encname, size_t len, char **result); utf8_convert_ret utf8_from_enc(const char *string, const char *encname, - size_t len, char **result); + size_t len, char **result, size_t *result_len); utf8_convert_ret utf8_to_html(const char *string, const char *encname, size_t len, char **result); |