summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/3rdparty/squirrel/squirrel/squtils.h2
-rw-r--r--src/3rdparty/squirrel/squirrel/sqvm.cpp14
2 files changed, 14 insertions, 2 deletions
diff --git a/src/3rdparty/squirrel/squirrel/squtils.h b/src/3rdparty/squirrel/squirrel/squtils.h
index b6a436e4a..55febe38c 100644
--- a/src/3rdparty/squirrel/squirrel/squtils.h
+++ b/src/3rdparty/squirrel/squirrel/squtils.h
@@ -88,7 +88,7 @@ public:
}
SQUnsignedInteger capacity() { return _allocated; }
inline T &back() const { return _vals[_size - 1]; }
- inline T& operator[](SQUnsignedInteger pos) const{ return _vals[pos]; }
+ inline T& operator[](SQUnsignedInteger pos) const{ assert(pos < _allocated); return _vals[pos]; }
T* _vals;
private:
void _realloc(SQUnsignedInteger newsize)
diff --git a/src/3rdparty/squirrel/squirrel/sqvm.cpp b/src/3rdparty/squirrel/squirrel/sqvm.cpp
index 2c277d996..720f21297 100644
--- a/src/3rdparty/squirrel/squirrel/sqvm.cpp
+++ b/src/3rdparty/squirrel/squirrel/sqvm.cpp
@@ -1526,7 +1526,19 @@ void SQVM::Pop(SQInteger n) {
}
}
-void SQVM::Push(const SQObjectPtr &o) { _stack[_top++] = o; }
+void SQVM::Push(const SQObjectPtr &o) {
+ /* Normally the stack shouldn't get this full, sometimes it might. As of now
+ * all cases have been bugs in "our" (OpenTTD) code. Trigger an assert for
+ * all debug builds and for the release builds just increase the stack size.
+ * This way getting a false positive isn't that bad (releases work fine) and
+ * if there is something fishy it can be caught in RCs/nightlies. */
+#ifdef NDEBUG
+ if (_top >= (int)_stack.capacity()) _stack.resize(2 * _stack.capacity());
+#else
+ assert(_top < (int)_stack.capacity());
+#endif
+ _stack[_top++] = o;
+}
SQObjectPtr &SQVM::Top() { return _stack[_top-1]; }
SQObjectPtr &SQVM::PopGet() { return _stack[--_top]; }
SQObjectPtr &SQVM::GetUp(SQInteger n) { return _stack[_top+n]; }