Codechange: replace printf with PRINTF macros by fmt::format for scripts
This commit is contained in:
@@ -196,7 +196,7 @@ char *ScriptText::_GetEncodedText(char *p, char *lastofp, int ¶m_count, Stri
|
||||
/* No more extra parameters, assume SQInteger are expected. */
|
||||
if (cur_idx >= this->paramc) throw Script_FatalError(fmt::format("{}: Not enough parameters", name));
|
||||
if (!std::holds_alternative<SQInteger>(this->param[cur_idx])) throw Script_FatalError(fmt::format("{}: Parameter {} expects an integer", name, param_count + i));
|
||||
p += seprintf(p, lastofp, ":" OTTD_PRINTFHEX64, std::get<SQInteger>(this->param[cur_idx++]));
|
||||
p = strecpy(p, fmt::format(":{:X}", std::get<SQInteger>(this->param[cur_idx++])).c_str(), lastofp);
|
||||
}
|
||||
}
|
||||
if (prev_idx == prev_count) {
|
||||
@@ -213,7 +213,7 @@ char *ScriptText::_GetEncodedText(char *p, char *lastofp, int ¶m_count, Stri
|
||||
case StringParam::STRING: {
|
||||
if (!std::holds_alternative<ScriptTextRef>(this->param[cur_idx])) throw Script_FatalError(fmt::format("{}: Parameter {} expects a substring", name, param_count));
|
||||
int count = 0;
|
||||
p += seprintf(p, lastofp, ":");
|
||||
p = strecpy(p, ":", lastofp);
|
||||
p = std::get<ScriptTextRef>(this->param[cur_idx++])->_GetEncodedText(p, lastofp, count, seen_ids);
|
||||
if (++count != cur_param.consumes) {
|
||||
ScriptLog::Error(fmt::format("{}: Parameter {} substring consumes {}, but expected {} to be consumed", name, param_count, count - 1, cur_param.consumes - 1).c_str());
|
||||
@@ -233,7 +233,7 @@ char *ScriptText::_GetEncodedText(char *p, char *lastofp, int ¶m_count, Stri
|
||||
if (cur_idx + cur_param.consumes > this->paramc) throw Script_FatalError(fmt::format("{}: Not enough parameters", name));
|
||||
for (int i = 0; i < cur_param.consumes; i++) {
|
||||
if (!std::holds_alternative<SQInteger>(this->param[cur_idx])) throw Script_FatalError(fmt::format("{}: Parameter {} expects an integer", name, param_count + i));
|
||||
p += seprintf(p, lastofp, ":" OTTD_PRINTFHEX64, std::get<SQInteger>(this->param[cur_idx++]));
|
||||
p = strecpy(p, fmt::format(":{:X}", std::get<SQInteger>(this->param[cur_idx++])).c_str(), lastofp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -74,12 +74,11 @@ struct ScriptAllocator {
|
||||
* already as then the allocation is for throwing that error in Squirrel, the
|
||||
* associated stack trace information and while cleaning up the AI. */
|
||||
this->error_thrown = true;
|
||||
char buff[128];
|
||||
seprintf(buff, lastof(buff), "Maximum memory allocation exceeded by " PRINTF_SIZE " bytes when allocating " PRINTF_SIZE " bytes",
|
||||
std::string msg = fmt::format("Maximum memory allocation exceeded by {} bytes when allocating {} bytes",
|
||||
this->allocated_size + requested_size - this->allocation_limit, requested_size);
|
||||
/* Don't leak the rejected allocation. */
|
||||
free(p);
|
||||
throw Script_FatalError(buff);
|
||||
throw Script_FatalError(msg);
|
||||
}
|
||||
|
||||
if (p == nullptr) {
|
||||
@@ -93,9 +92,8 @@ struct ScriptAllocator {
|
||||
}
|
||||
|
||||
this->error_thrown = true;
|
||||
char buff[64];
|
||||
seprintf(buff, lastof(buff), "Out of memory. Cannot allocate " PRINTF_SIZE " bytes", requested_size);
|
||||
throw Script_FatalError(buff);
|
||||
std::string msg = fmt::format("Out of memory. Cannot allocate {} bytes", requested_size);
|
||||
throw Script_FatalError(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user