Skip to content

Commit f983b78

Browse files
null-terminate JSON string in rdb_save (RedisJSON#643)
* null-terminate JSON string in rdb_save * Review (avoid unneeded ref) Co-authored-by: Meir Shpilraien (Spielrein) <meir@redislabs.com> Co-authored-by: Meir Shpilraien (Spielrein) <meir@redislabs.com>
1 parent 131f779 commit f983b78

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/redisjson.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub struct RedisJSON<T> {
123123

124124
pub mod type_methods {
125125
use super::*;
126-
use std::ptr::null_mut;
126+
use std::{ffi::CString, ptr::null_mut};
127127

128128
pub extern "C" fn rdb_load(rdb: *mut raw::RedisModuleIO, encver: c_int) -> *mut c_void {
129129
let json_string = value_rdb_load_json(rdb, encver);
@@ -221,7 +221,8 @@ pub mod type_methods {
221221
String::from_utf8(out.into_inner()).unwrap()
222222
}
223223
};
224-
raw::save_string(rdb, &json);
224+
let cjson = CString::new(json).unwrap();
225+
raw::save_string(rdb, cjson.to_str().unwrap());
225226
}
226227

227228
#[allow(non_snake_case, unused)]

0 commit comments

Comments
 (0)