diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-10-31 08:24:55 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-10-31 08:24:55 +0400 |
commit | ac86beb0e569075e2bd6e2da914bda2831b06c18 (patch) | |
tree | ff3164f3bd225601312acf357d11af697d1f95e6 /source/blender/blenlib/intern | |
parent | e8a70d4b90161224f4b6c5a73b00d7673cbbcc70 (diff) |
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/string_utf8.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c index 5684b12cc8b..a8960f1abbb 100644 --- a/source/blender/blenlib/intern/string_utf8.c +++ b/source/blender/blenlib/intern/string_utf8.c @@ -184,6 +184,8 @@ char *BLI_strncpy_utf8(char *dst, const char *src, size_t maxncpy) { char *dst_r = dst; + BLI_assert(maxncpy != 0); + /* note: currently we don't attempt to deal with invalid utf8 chars */ BLI_STR_UTF8_CPY(dst, src, maxncpy); @@ -207,10 +209,13 @@ char *BLI_strncat_utf8(char *dst, const char *src, size_t maxncpy) /* --------------------------------------------------------------------------*/ /* wchar_t / utf8 functions */ -size_t BLI_strncpy_wchar_as_utf8(char *dst, const wchar_t *src, const size_t maxcpy) +size_t BLI_strncpy_wchar_as_utf8(char *dst, const wchar_t *src, const size_t maxncpy) { size_t len = 0; - while (*src && len < maxcpy) { /* XXX can still run over the buffer because utf8 size isn't known :| */ + + BLI_assert(maxncpy != 0); + + while (*src && len < maxncpy) { /* XXX can still run over the buffer because utf8 size isn't known :| */ len += BLI_str_utf8_from_unicode(*src++, dst + len); } @@ -280,7 +285,7 @@ size_t BLI_strnlen_utf8(const char *start, const size_t maxlen) return len; } -size_t BLI_strncpy_wchar_from_utf8(wchar_t *dst_w, const char *src_c, const size_t maxcpy) +size_t BLI_strncpy_wchar_from_utf8(wchar_t *dst_w, const char *src_c, const size_t maxncpy) { int len = 0; @@ -288,7 +293,7 @@ size_t BLI_strncpy_wchar_from_utf8(wchar_t *dst_w, const char *src_c, const size return 0; } - while (*src_c && len < maxcpy) { + while (*src_c && len < maxncpy) { size_t step = 0; unsigned int unicode = BLI_str_utf8_as_unicode_and_size(src_c, &step); if (unicode != BLI_UTF8_ERR) { |