Fix UI crash entering very long strings

Strings exceeding UI_MAX_DRAW_STR weren't null terminated.
This commit is contained in:
Campbell Barton 2015-09-18 16:30:47 +10:00 committed by Sergey Sharybin
parent 141de0cc7f
commit 07c3311475
1 changed files with 7 additions and 1 deletions

View File

@ -2156,8 +2156,14 @@ void ui_but_string_get_ex(uiBut *but, char *str, const size_t maxlen, const int
str[0] = '\0';
}
else if (buf && buf != str) {
BLI_assert(maxlen <= buf_len + 1);
/* string was too long, we have to truncate */
memcpy(str, buf, MIN2(maxlen, (size_t)(buf_len + 1)));
if (ui_but_is_utf8(but)) {
BLI_strncpy_utf8(str, buf, maxlen);
}
else {
BLI_strncpy(str, buf, maxlen);
}
MEM_freeN((void *)buf);
}
}