Mercurial > hg > openttd
changeset 18127:098d8919f276 draft
(svn r22952) -Fix: properly limit the length of strings in a choice list
author | yexo <yexo@openttd.org> |
---|---|
date | Fri, 23 Sep 2011 12:26:25 +0000 |
parents | 7a58bed50627 |
children | c1f813e228e8 |
files | src/newgrf_text.cpp |
diffstat | 1 files changed, 3 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -371,7 +371,9 @@ for (int i = 0; i < count; i++) { int idx = (this->type == SCC_GENDER_LIST ? lm->GetReverseMapping(i, true) : i + 1); const char *str = this->strings[this->strings.Contains(idx) ? idx : 0]; - size_t len = strlen(str); + /* Limit the length of the string we copy to 0xFE. The length is written above + * as a byte and we need room for the final '\0'. */ + size_t len = min(0xFE, strlen(str)); memcpy(d, str, len); d += len; *d++ = '\0';