1
0
Fork 0

(svn r26238) -Codechange: Use StringParameters::GetDataLeft to check for left space in the param array.

release/1.4
frosch 2014-01-12 17:59:43 +00:00
parent bc86bf9b12
commit 5ab39cc651
2 changed files with 9 additions and 3 deletions

View File

@ -1022,7 +1022,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
/* WARNING. It's prohibited for the included string to consume any arguments. /* WARNING. It's prohibited for the included string to consume any arguments.
* For included strings that consume argument, you should use STRING1, STRING2 etc. * For included strings that consume argument, you should use STRING1, STRING2 etc.
* To debug stuff you can set argv to NULL and it will tell you */ * To debug stuff you can set argv to NULL and it will tell you */
StringParameters tmp_params(args->GetDataPointer(), args->num_param - args->offset, NULL); StringParameters tmp_params(args->GetDataPointer(), args->GetDataLeft(), NULL);
buff = GetStringWithArgs(buff, str, &tmp_params, last, next_substr_case_index, game_script); buff = GetStringWithArgs(buff, str, &tmp_params, last, next_substr_case_index, game_script);
next_substr_case_index = 0; next_substr_case_index = 0;
break; break;
@ -1039,7 +1039,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
StringID str = args->GetInt32(b); StringID str = args->GetInt32(b);
if (game_script && GB(str, TAB_COUNT_OFFSET, TAB_COUNT_BITS) != GAME_TEXT_TAB) break; if (game_script && GB(str, TAB_COUNT_OFFSET, TAB_COUNT_BITS) != GAME_TEXT_TAB) break;
uint size = b - SCC_STRING1 + 1; uint size = b - SCC_STRING1 + 1;
if (game_script && size > args->num_param - args->offset) { if (game_script && size > args->GetDataLeft()) {
buff = strecat(buff, "(too many parameters)", last); buff = strecat(buff, "(too many parameters)", last);
} else { } else {
StringParameters sub_args(*args, size); StringParameters sub_args(*args, size);

View File

@ -56,7 +56,7 @@ public:
offset(0), offset(0),
num_param(size) num_param(size)
{ {
assert(size <= parent.num_param - parent.offset); assert(size <= parent.GetDataLeft());
if (parent.type == NULL) { if (parent.type == NULL) {
this->type = NULL; this->type = NULL;
} else { } else {
@ -89,6 +89,12 @@ public:
return &this->data[this->offset]; return &this->data[this->offset];
} }
/** Return the amount of elements which can still be read. */
uint GetDataLeft() const
{
return this->num_param - this->offset;
}
/** Get a pointer to a specific element in the data array. */ /** Get a pointer to a specific element in the data array. */
uint64 *GetPointerToOffset(uint offset) const uint64 *GetPointerToOffset(uint offset) const
{ {