Force protected mode for long enough strings

This commit is contained in:
Alex Orlenko 2023-02-06 23:46:31 +00:00
parent 47c8300ccf
commit f5182e0584
No known key found for this signature in database
GPG Key ID: 4C150C250863B96D
1 changed files with 2 additions and 1 deletions

View File

@ -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());
})