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).
This commit is contained in:
Bastien Montagne 2015-01-05 21:38:15 +01:00
parent e7a9bf88d2
commit c91e64faa6

@ -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);
}
}
}
}