diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2008-06-26 15:58:06 -0400 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2008-06-26 16:20:59 -0400 |
commit | dff0dd0c63e530e21471531299a8f260cf88f001 (patch) | |
tree | 73e05e520fd547b4dc2a10a4eafe88bf1a6c1e46 /src/cairo-unicode.c | |
parent | 883c972a9bc0aafb817a02c7b4a8c6f250796405 (diff) |
Allow NULL output in _cairo_utf8_to_ucs4()
The function can be used to validate UTF-8 text now.
Diffstat (limited to 'src/cairo-unicode.c')
-rw-r--r-- | src/cairo-unicode.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/cairo-unicode.c b/src/cairo-unicode.c index caa4727d..c4873d5c 100644 --- a/src/cairo-unicode.c +++ b/src/cairo-unicode.c @@ -202,7 +202,7 @@ _utf8_get_char_extended (const unsigned char *p, * If @len is supplied and the string has an embedded nul * byte, only the portion before the nul byte is converted. * @result: location to store a pointer to a newly allocated UTF-32 - * string (always native endian). Free with free(). A 0 + * string (always native endian), or %NULL. Free with free(). A 0 * word will be written after the last character. * @items_written: location to store number of 32-bit words * written. (Not including the trailing 0) @@ -241,18 +241,21 @@ _cairo_utf8_to_ucs4 (const char *str, in = UTF8_NEXT_CHAR (in); } - str32 = _cairo_malloc_ab (n_chars + 1, sizeof (uint32_t)); - if (!str32) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); + if (result) { + str32 = _cairo_malloc_ab (n_chars + 1, sizeof (uint32_t)); + if (!str32) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); - in = ustr; - for (i=0; i < n_chars; i++) { - str32[i] = _utf8_get_char (in); - in = UTF8_NEXT_CHAR (in); + in = ustr; + for (i=0; i < n_chars; i++) { + str32[i] = _utf8_get_char (in); + in = UTF8_NEXT_CHAR (in); + } + str32[i] = 0; + + *result = str32; } - str32[i] = 0; - *result = str32; if (items_written) *items_written = n_chars; |