Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2015-02-27 23:31:54 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-02-27 23:31:54 +0300
commit12f60e7825aa2db3cb1b8dc84ba983fb72e9f41c (patch)
tree88f67907e7b2f508398bc9c20b4f7821ad887f45 /source/blender/blenlib/intern/string_utf8.c
parent15957a9e4d640af223b0ff0b893139d436cab7fb (diff)
Fix T43834: Text object looses one char after another by entering/leaving edit mode.
Own mistake in refactoring of `BLI_strncpy_wchar_as_utf8()`, if given size was exactly the one needed, we'd lost last char (off-by-one error). Many thanks to plasmasolutions (Thomas Beck) who found the issue and did all the investigation work here!
Diffstat (limited to 'source/blender/blenlib/intern/string_utf8.c')
-rw-r--r--source/blender/blenlib/intern/string_utf8.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c
index c93c3cf628c..67ff532cb6f 100644
--- a/source/blender/blenlib/intern/string_utf8.c
+++ b/source/blender/blenlib/intern/string_utf8.c
@@ -249,7 +249,7 @@ char *BLI_strncat_utf8(char *__restrict dst, const char *__restrict src, size_t
size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict src, const size_t maxncpy)
{
const size_t maxlen = maxncpy - 1;
- const size_t maxlen_secured = ((int)maxlen - 6) < 0 ? 0 : maxlen - 6; /* 6 is max utf8 length of an unicode char. */
+ const int64_t maxlen_secured = (int64_t)maxlen - 6; /* 6 is max utf8 length of an unicode char. */
size_t len = 0;
BLI_assert(maxncpy != 0);
@@ -258,7 +258,7 @@ size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict
memset(dst, 0xff, sizeof(*dst) * maxncpy);
#endif
- while (*src && len < maxlen_secured) {
+ while (*src && len <= maxlen_secured) {
len += BLI_str_utf8_from_unicode((unsigned int)*src++, dst + len);
}
@@ -268,7 +268,7 @@ size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict
char t[6];
size_t l = BLI_str_utf8_from_unicode((unsigned int)*src++, t);
BLI_assert(l <= 6);
- if (len + l >= maxlen) {
+ if (len + l > maxlen) {
break;
}
memcpy(dst + len, t, l);