Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .agents/tasks/2025/06/29-2309-cstring-error
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Create CString objects for error strings before passing them to rb_raise
18 changes: 12 additions & 6 deletions gems/codetracer-ruby-recorder/ext/native_tracer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,18 +685,24 @@ unsafe extern "C" fn flush_trace(self_val: VALUE, out_dir: VALUE, format: VALUE)
match std::str::from_utf8(slice) {
Ok(path_str) => {
if let Err(e) = flush_to_dir(&recorder.tracer, Path::new(path_str), fmt) {
let msg = std::ffi::CString::new(e.to_string())
.unwrap_or_else(|_| std::ffi::CString::new("unknown error").unwrap());
rb_raise(
rb_eIOError,
b"Failed to flush trace: %s\0".as_ptr() as *const c_char,
e.to_string().as_ptr() as *const c_char,
msg.as_ptr(),
);
}
}
Err(e) => rb_raise(
rb_eIOError,
b"Invalid UTF-8 in path: %s\0".as_ptr() as *const c_char,
e.to_string().as_ptr() as *const c_char,
),
Err(e) => {
let msg = std::ffi::CString::new(e.to_string())
.unwrap_or_else(|_| std::ffi::CString::new("invalid utf8").unwrap());
rb_raise(
rb_eIOError,
b"Invalid UTF-8 in path: %s\0".as_ptr() as *const c_char,
msg.as_ptr(),
)
},
}

Qnil.into()
Expand Down
Loading