mirror of https://github.com/OpenTTD/OpenTTD
Change: [Script] A ScriptText with too many parameters is now a fatal error
It should never happen as adding/setting parameters already checks that anyway.pull/10491/head
parent
2fdfc38da8
commit
e735370318
|
@ -20,6 +20,9 @@
|
||||||
* API additions:
|
* API additions:
|
||||||
* \li AITown::ROAD_LAYOUT_RANDOM
|
* \li AITown::ROAD_LAYOUT_RANDOM
|
||||||
*
|
*
|
||||||
|
* API removals:
|
||||||
|
* \li AIError::ERR_PRECONDITION_TOO_MANY_PARAMETERS, that error is never returned anymore.
|
||||||
|
*
|
||||||
* \b 13.0
|
* \b 13.0
|
||||||
*
|
*
|
||||||
* API additions:
|
* API additions:
|
||||||
|
|
|
@ -20,6 +20,9 @@
|
||||||
* API additions:
|
* API additions:
|
||||||
* \li GSTown::ROAD_LAYOUT_RANDOM
|
* \li GSTown::ROAD_LAYOUT_RANDOM
|
||||||
*
|
*
|
||||||
|
* API removals:
|
||||||
|
* \li GSError::ERR_PRECONDITION_TOO_MANY_PARAMETERS, that error is never returned anymore.
|
||||||
|
*
|
||||||
* \b 13.0
|
* \b 13.0
|
||||||
*
|
*
|
||||||
* API additions:
|
* API additions:
|
||||||
|
|
|
@ -42,10 +42,6 @@
|
||||||
* @param string The string that is checked.
|
* @param string The string that is checked.
|
||||||
*/
|
*/
|
||||||
#define EnforcePreconditionEncodedText(returnval, string) \
|
#define EnforcePreconditionEncodedText(returnval, string) \
|
||||||
if ((string) == nullptr) { \
|
|
||||||
ScriptObject::SetLastError(ScriptError::ERR_PRECONDITION_TOO_MANY_PARAMETERS); \
|
|
||||||
return returnval; \
|
|
||||||
} \
|
|
||||||
if (StrEmpty(string)) { \
|
if (StrEmpty(string)) { \
|
||||||
ScriptObject::SetLastError(ScriptError::ERR_PRECONDITION_FAILED); \
|
ScriptObject::SetLastError(ScriptError::ERR_PRECONDITION_FAILED); \
|
||||||
return returnval; \
|
return returnval; \
|
||||||
|
@ -94,8 +90,6 @@ public:
|
||||||
ERR_PRECONDITION_FAILED, // []
|
ERR_PRECONDITION_FAILED, // []
|
||||||
/** A string supplied was too long */
|
/** A string supplied was too long */
|
||||||
ERR_PRECONDITION_STRING_TOO_LONG, // []
|
ERR_PRECONDITION_STRING_TOO_LONG, // []
|
||||||
/** A string had too many parameters */
|
|
||||||
ERR_PRECONDITION_TOO_MANY_PARAMETERS, // []
|
|
||||||
/** The company you use is invalid */
|
/** The company you use is invalid */
|
||||||
ERR_PRECONDITION_INVALID_COMPANY, // []
|
ERR_PRECONDITION_INVALID_COMPANY, // []
|
||||||
/** An error returned by a NewGRF. No possibility to get the exact error in an script readable format */
|
/** An error returned by a NewGRF. No possibility to get the exact error in an script readable format */
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "../../string_func.h"
|
#include "../../string_func.h"
|
||||||
#include "../../strings_func.h"
|
#include "../../strings_func.h"
|
||||||
#include "script_text.hpp"
|
#include "script_text.hpp"
|
||||||
|
#include "../script_fatalerror.hpp"
|
||||||
#include "../../table/control_codes.h"
|
#include "../../table/control_codes.h"
|
||||||
|
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
@ -181,7 +182,8 @@ const char *ScriptText::GetEncodedText()
|
||||||
static char buf[1024];
|
static char buf[1024];
|
||||||
int param_count = 0;
|
int param_count = 0;
|
||||||
this->_GetEncodedText(buf, lastof(buf), param_count);
|
this->_GetEncodedText(buf, lastof(buf), param_count);
|
||||||
return (param_count > SCRIPT_TEXT_MAX_PARAMETERS) ? nullptr : buf;
|
if (param_count > SCRIPT_TEXT_MAX_PARAMETERS) throw Script_FatalError("A string had too many parameters");
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ScriptText::_GetEncodedText(char *p, char *lastofp, int ¶m_count)
|
char *ScriptText::_GetEncodedText(char *p, char *lastofp, int ¶m_count)
|
||||||
|
@ -208,8 +210,7 @@ char *ScriptText::_GetEncodedText(char *p, char *lastofp, int ¶m_count)
|
||||||
|
|
||||||
const char *Text::GetDecodedText()
|
const char *Text::GetDecodedText()
|
||||||
{
|
{
|
||||||
const char *encoded_text = this->GetEncodedText();
|
const std::string &encoded_text = this->GetEncodedText();
|
||||||
if (encoded_text == nullptr) return nullptr;
|
|
||||||
|
|
||||||
static char buf[1024];
|
static char buf[1024];
|
||||||
::SetDParamStr(0, encoded_text);
|
::SetDParamStr(0, encoded_text);
|
||||||
|
|
Loading…
Reference in New Issue