Skip to content

Commit 5774489

Browse files
committed
Simple string write
1 parent 5d2d9e9 commit 5774489

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

datadog-crashtracker/src/runtime_callback.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,18 @@ pub(crate) unsafe fn invoke_runtime_callback_with_writer<W: std::io::Write>(
352352
});
353353
}
354354

355-
// Define the emit_stacktrace_string function that writes directly to the pipe
356355
unsafe extern "C" fn emit_stacktrace_string_collector(stacktrace_string: *const c_char) {
357-
let stacktrace_string_str = std::ffi::CStr::from_ptr(stacktrace_string);
358-
let stacktrace_string_str = stacktrace_string_str.to_str().unwrap();
356+
if stacktrace_string.is_null() {
357+
return;
358+
}
359+
360+
let cstr = std::ffi::CStr::from_ptr(stacktrace_string);
361+
let bytes = cstr.to_bytes();
362+
359363
FRAME_WRITER.with(|writer_cell| {
360364
if let Some(writer_ptr) = *writer_cell.borrow() {
361365
let writer = &mut *writer_ptr;
362-
let _ = writer.write_all(stacktrace_string_str.as_bytes());
366+
let _ = writer.write_all(bytes);
363367
let _ = writer.flush();
364368
}
365369
});

0 commit comments

Comments
 (0)