From da17692a3df059bf6810998c4abff74cb741292d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Aug 2021 20:37:51 +1000 Subject: Cleanup: use BLI_UTF8_MAX define --- source/blender/blenlib/intern/string_utf8.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c index cc6a192f6ba..e35e2bcca3c 100644 --- a/source/blender/blenlib/intern/string_utf8.c +++ b/source/blender/blenlib/intern/string_utf8.c @@ -297,8 +297,8 @@ size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const size_t maxncpy) { const size_t maxlen = maxncpy - 1; - /* 6 is max utf8 length of an unicode char. */ - const int64_t maxlen_secured = (int64_t)maxlen - 6; + /* #BLI_UTF8_MAX is max utf8 length of an unicode char. */ + const int64_t maxlen_secured = (int64_t)maxlen - BLI_UTF8_MAX; size_t len = 0; BLI_assert(maxncpy != 0); @@ -314,9 +314,9 @@ size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, /* We have to be more careful for the last six bytes, * to avoid buffer overflow in case utf8-encoded char would be too long for our dst buffer. */ while (*src) { - char t[6]; + char t[BLI_UTF8_MAX]; size_t l = BLI_str_utf8_from_unicode((uint)*src++, t); - BLI_assert(l <= 6); + BLI_assert(l <= BLI_UTF8_MAX); if (len + l > maxlen) { break; } @@ -707,8 +707,8 @@ size_t BLI_str_utf32_as_utf8(char *__restrict dst, const size_t maxncpy) { const size_t maxlen = maxncpy - 1; - /* 6 is max utf8 length of an unicode char. */ - const int64_t maxlen_secured = (int64_t)maxlen - 6; + /* #BLI_UTF8_MAX is max utf8 length of an unicode char. */ + const int64_t maxlen_secured = (int64_t)maxlen - BLI_UTF8_MAX; size_t len = 0; BLI_assert(maxncpy != 0); @@ -724,9 +724,9 @@ size_t BLI_str_utf32_as_utf8(char *__restrict dst, /* We have to be more careful for the last six bytes, * to avoid buffer overflow in case utf8-encoded char would be too long for our dst buffer. */ while (*src) { - char t[6]; + char t[BLI_UTF8_MAX]; size_t l = BLI_str_utf8_from_unicode((uint)*src++, t); - BLI_assert(l <= 6); + BLI_assert(l <= BLI_UTF8_MAX); if (len + l > maxlen) { break; } -- cgit v1.2.3