[Bf-blender-cvs] [c91e64f] master: Fix/cleanup very ugly and unsafe usage of but->str in ui_but_update().

Bastien Montagne noreply at git.blender.org
Mon Jan 5 21:50:08 CET 2015


Commit: c91e64faa612aabac3f99a0b607d42303f945ac9
Author: Bastien Montagne
Date:   Mon Jan 5 21:38:15 2015 +0100
Branches: master
https://developer.blender.org/rBc91e64faa612aabac3f99a0b607d42303f945ac9

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).

===================================================================

M	source/blender/editors/interface/interface.c

===================================================================

diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index e730182..5016186 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);
+							}
 						}
 					}
 				}




More information about the Bf-blender-cvs mailing list