(svn r17095) -Codechange: make ParseStringChoice a bit safer

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
rubidium 15 years ago
parent 6ae880a40d
commit ee2b7de8f4

@ -327,9 +327,10 @@ static int TranslateArgumentIdx(int arg);
static void EmitWordList(const char * const *words, uint nw)
{
PutByte(nw);
for (uint i = 0; i < nw; i++) PutByte(strlen(words[i]));
for (uint i = 0; i < nw; i++) PutByte(strlen(words[i]) + 1);
for (uint i = 0; i < nw; i++) {
for (uint j = 0; words[i][j] != '\0'; j++) PutByte(words[i][j]);
PutByte(0);
}
}

@ -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)
{
/* <NUM> {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;
}

Loading…
Cancel
Save