summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Orlenko <zxteam@protonmail.com>2023-02-06 23:46:31 +0000
committerAlex Orlenko <zxteam@protonmail.com>2023-02-06 23:46:31 +0000
commitf5182e0584ae4250dbbff95d38d11909571425a5 (patch)
treef92d23645f360d803ae1e46665dc8dde9fc42482
parent47c8300ccf6efa795371442cb59580aa8da22634 (diff)
downloadmlua-f5182e0584ae4250dbbff95d38d11909571425a5.zip
Force protected mode for long enough strings
-rw-r--r--src/util.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/util.rs b/src/util.rs
index f793264..547afe3 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -230,7 +230,8 @@ pub unsafe fn pop_error(state: *mut ffi::lua_State, err_code: c_int) -> Error {
// Uses 3 (or 1 if unprotected) stack spaces, does not call checkstack.
#[inline(always)]
pub unsafe fn push_string(state: *mut ffi::lua_State, s: &[u8], protect: bool) -> Result<()> {
- if protect {
+ // Always use protected mode if the string is too long
+ if protect || s.len() > (1 << 30) {
protect_lua!(state, 0, 1, |state| {
ffi::lua_pushlstring(state, s.as_ptr() as *const c_char, s.len());
})