From ee2b7de8f41a6ccee5522e0de53cf5476e041350 Mon Sep 17 00:00:00 2001 From: rubidium Date: Thu, 6 Aug 2009 20:21:53 +0000 Subject: (svn r17095) -Codechange: make ParseStringChoice a bit safer --- src/strings.cpp | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'src/strings.cpp') diff --git a/src/strings.cpp b/src/strings.cpp index 25c992e44..e05229f1b 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -190,7 +190,7 @@ static char *FormatNumber(char *buff, int64 number, const char *last, const char uint64 num; if (number < 0) { - *buff++ = '-'; + buff += seprintf(buff, last, "-"); number = -number; } @@ -460,22 +460,19 @@ static int DeterminePluralForm(int64 count) } } -static const char *ParseStringChoice(const char *b, uint form, char *dst, int *dstlen) +static const char *ParseStringChoice(const char *b, uint form, char **dst, const char *last) { /* {Length of each string} {each string} */ uint n = (byte)*b++; - uint pos, i, mylen = 0, mypos = 0; + uint pos, i, mypos = 0; for (i = pos = 0; i != n; i++) { uint len = (byte)*b++; - if (i == form) { - mypos = pos; - mylen = len; - } + if (i == form) mypos = pos; pos += len; } - *dstlen = mylen; - memcpy(dst, b + mypos, mylen); + + *dst += seprintf(*dst, last, "%s", b + mypos); return b + pos; } @@ -717,7 +714,6 @@ static char *FormatString(char *buff, const char *str, int64 *argv, uint casei, case SCC_GENDER_LIST: { // {G 0 Der Die Das} const char *s = GetStringPtr(argv_orig[(byte)*str++]); // contains the string that determines gender. - int len; int gender = 0; if (s != NULL) { wchar_t c = Utf8Consume(&s); @@ -731,8 +727,7 @@ static char *FormatString(char *buff, const char *str, int64 *argv, uint casei, /* Does this string have a gender, if so, set it */ if (c == SCC_GENDER_INDEX) gender = (byte)s[0]; } - str = ParseStringChoice(str, gender, buff, &len); - buff += len; + str = ParseStringChoice(str, gender, &buff, last); break; } @@ -831,9 +826,7 @@ static char *FormatString(char *buff, const char *str, int64 *argv, uint casei, case SCC_PLURAL_LIST: { // {P} int64 v = argv_orig[(byte)*str++]; // contains the number that determines plural - int len; - str = ParseStringChoice(str, DeterminePluralForm(v), buff, &len); - buff += len; + str = ParseStringChoice(str, DeterminePluralForm(v), &buff, last); break; } -- cgit v1.2.3-54-g00ecf