From c91e64faa612aabac3f99a0b607d42303f945ac9 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 5 Jan 2015 21:38:15 +0100 Subject: Fix/cleanup very ugly and unsafe usage of but->str in ui_but_update(). Currently, but->str should never be smaller than but->strdata, but code shall not rely on this. Further more, but->strdata is 'only' 128 chars, this could become limit with some translations, if the org label is already rather long, leading to truncated str (Chinese e.g. can only store about 40 chars in strdata). --- source/blender/editors/interface/interface.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'source/blender/editors') diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index e730182ae37..50161863872 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -2647,7 +2647,18 @@ void ui_but_update(uiBut *but) if (RNA_property_enum_name_gettexted(but->block->evil_C, &but->rnapoin, but->rnaprop, value, &buf)) { - BLI_strncpy(but->str, buf, sizeof(but->strdata)); + if (but->str == but->strdata) { + if (strlen(buf) < sizeof(but->strdata)) { + BLI_strncpy(but->str, buf, sizeof(but->strdata)); + } + else { + but->str = BLI_strdup(buf); + } + } + else { + MEM_SAFE_FREE(but->str); + but->str = BLI_strdup(buf); + } } } } -- cgit v1.2.3