mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r18502) -Fix: the dummy AI would could a NOT_REACHED if the translated error message contained a quote
This commit is contained in:
parent
4250792389
commit
c0d4bc5b87
|
@ -63,6 +63,15 @@ void AI_CreateAIDummy(HSQUIRRELVM vm)
|
||||||
char error_message[1024];
|
char error_message[1024];
|
||||||
GetString(error_message, STR_ERROR_AI_NO_AI_FOUND, lastof(error_message));
|
GetString(error_message, STR_ERROR_AI_NO_AI_FOUND, lastof(error_message));
|
||||||
|
|
||||||
|
/* Make escapes for all quotes and slashes. */
|
||||||
|
char safe_error_message[1024];
|
||||||
|
char *q = safe_error_message;
|
||||||
|
for (const char *p = error_message; *p != '\0' && q < lastof(safe_error_message) - 2; p++, q++) {
|
||||||
|
if (*p == '"' || *p == '\\') *q++ = '\\';
|
||||||
|
*q = *p;
|
||||||
|
}
|
||||||
|
*q = '\0';
|
||||||
|
|
||||||
/* 2) We construct the AI's code. This is done by merging a header, body and footer */
|
/* 2) We construct the AI's code. This is done by merging a header, body and footer */
|
||||||
char dummy_script[4096];
|
char dummy_script[4096];
|
||||||
char *dp = dummy_script;
|
char *dp = dummy_script;
|
||||||
|
@ -71,7 +80,7 @@ void AI_CreateAIDummy(HSQUIRRELVM vm)
|
||||||
/* As special trick we need to split the error message on newlines and
|
/* As special trick we need to split the error message on newlines and
|
||||||
* emit each newline as a separate error printing string. */
|
* emit each newline as a separate error printing string. */
|
||||||
char *newline;
|
char *newline;
|
||||||
char *p = error_message;
|
char *p = safe_error_message;
|
||||||
do {
|
do {
|
||||||
newline = strchr(p, '\n');
|
newline = strchr(p, '\n');
|
||||||
if (newline != NULL) *newline = '\0';
|
if (newline != NULL) *newline = '\0';
|
||||||
|
|
Loading…
Reference in New Issue