summaryrefslogtreecommitdiff
path: root/src/script/api
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-05-16 11:58:44 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-05-30 10:15:22 +0200
commit29f2bd27c44ef51f8af1299cf16012a4fa89cc61 (patch)
tree71696926717dacf9db2ee80273ac8d11a1b93b8e /src/script/api
parent8a918ce1709cb80191ba8e5195ec8ef02d484d9e (diff)
downloadopenttd-29f2bd27c44ef51f8af1299cf16012a4fa89cc61.tar.xz
Codechange: [Game] Pass the length instead of '\0' terminating (and undoing that) in the middle of a C-string
Diffstat (limited to 'src/script/api')
-rw-r--r--src/script/api/script_event_types.cpp17
-rw-r--r--src/script/api/script_event_types.hpp6
2 files changed, 11 insertions, 12 deletions
diff --git a/src/script/api/script_event_types.cpp b/src/script/api/script_event_types.cpp
index 84c001836..84d6d99cd 100644
--- a/src/script/api/script_event_types.cpp
+++ b/src/script/api/script_event_types.cpp
@@ -134,7 +134,7 @@ ScriptEventAdminPort::~ScriptEventAdminPort()
SQInteger ScriptEventAdminPort::GetObject(HSQUIRRELVM vm)
{
- char *p = this->json;
+ const char *p = this->json;
if (this->ReadTable(vm, p) == nullptr) {
sq_pushnull(vm);
@@ -144,9 +144,9 @@ SQInteger ScriptEventAdminPort::GetObject(HSQUIRRELVM vm)
return 1;
}
-char *ScriptEventAdminPort::ReadString(HSQUIRRELVM vm, char *p)
+const char *ScriptEventAdminPort::ReadString(HSQUIRRELVM vm, const char *p)
{
- char *value = p;
+ const char *value = p;
bool escape = false;
for (;;) {
@@ -168,14 +168,13 @@ char *ScriptEventAdminPort::ReadString(HSQUIRRELVM vm, char *p)
p++;
}
- *p = '\0';
- sq_pushstring(vm, value, -1);
- *p++ = '"';
+ sq_pushstring(vm, value, p - value);
+ p++; // Step past the end-of-string marker (")
return p;
}
-char *ScriptEventAdminPort::ReadTable(HSQUIRRELVM vm, char *p)
+const char *ScriptEventAdminPort::ReadTable(HSQUIRRELVM vm, const char *p)
{
sq_newtable(vm);
@@ -218,7 +217,7 @@ char *ScriptEventAdminPort::ReadTable(HSQUIRRELVM vm, char *p)
return p;
}
-char *ScriptEventAdminPort::ReadValue(HSQUIRRELVM vm, char *p)
+const char *ScriptEventAdminPort::ReadValue(HSQUIRRELVM vm, const char *p)
{
SKIP_EMPTY(p);
@@ -257,7 +256,7 @@ char *ScriptEventAdminPort::ReadValue(HSQUIRRELVM vm, char *p)
sq_newarray(vm, 0);
/* Empty array? */
- char *p2 = p + 1;
+ const char *p2 = p + 1;
SKIP_EMPTY(p2);
if (*p2 == ']') {
p = p2 + 1;
diff --git a/src/script/api/script_event_types.hpp b/src/script/api/script_event_types.hpp
index 1d514389b..b6ed7bfbc 100644
--- a/src/script/api/script_event_types.hpp
+++ b/src/script/api/script_event_types.hpp
@@ -860,21 +860,21 @@ private:
* @param vm The VM used.
* @param p The (part of the) JSON string reading.
*/
- char *ReadTable(HSQUIRRELVM vm, char *p);
+ const char *ReadTable(HSQUIRRELVM vm, const char *p);
/**
* Read a value from a JSON string.
* @param vm The VM used.
* @param p The (part of the) JSON string reading.
*/
- char *ReadValue(HSQUIRRELVM vm, char *p);
+ const char *ReadValue(HSQUIRRELVM vm, const char *p);
/**
* Read a string from a JSON string.
* @param vm The VM used.
* @param p The (part of the) JSON string reading.
*/
- char *ReadString(HSQUIRRELVM vm, char *p);
+ const char *ReadString(HSQUIRRELVM vm, const char *p);
};
/**