Skip to content

Commit f8b40c6

Browse files
committed
don't drop temporary CString too early
1 parent 347786a commit f8b40c6

File tree

1 file changed

+3
-8
lines changed
  • test-libz-rs-sys/src

1 file changed

+3
-8
lines changed

test-libz-rs-sys/src/gz.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ use libz_rs_sys::gzopen;
55
use std::ffi::CString;
66
use std::ptr;
77

8-
// Turn a Rust string into a C string
9-
macro_rules! cs {
10-
($str:expr) => {
11-
CString::new($str).unwrap().as_ptr()
12-
};
13-
}
14-
158
// Generate a file path relative to the project's root
169
macro_rules! path {
1710
($str:expr) => {
@@ -20,7 +13,9 @@ macro_rules! path {
2013
}
2114

2215
unsafe fn test_open(path: &str, mode: &str, should_succeed: bool) {
23-
let handle = gzopen(cs!(path), cs!(mode));
16+
let cpath = CString::new(path).unwrap();
17+
let cmode = CString::new(mode).unwrap();
18+
let handle = gzopen(cpath.as_ptr(), cmode.as_ptr());
2419
assert_eq!(should_succeed, !handle.is_null(), "{path} {mode}");
2520
if !handle.is_null() {
2621
assert_eq!(gzclose(handle), Z_OK);

0 commit comments

Comments
 (0)