Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the dst type, which is expected to be *mut i8 #195

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion gentl/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl CopyTo for &str {
if *dst_size < string_len {
return Err(GenTlError::BufferTooSmall);
}
std::ptr::copy_nonoverlapping(self.as_ptr().cast::<i8>(), dst, self.len());
std::ptr::copy_nonoverlapping(self.as_ptr().cast::<i8>(), dst.cast::<i8>(), self.len());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, libc::c_char can be an i8 or a u8 depending on the platform.

&str.as_ptr() always returns a *const u8 as far as I'm aware, so it almost makes more sense to cast dst to a u8 pointer and remove the cast on self.as_ptr().

To be honest this whole function feels a bit precarious and should probably be using CString and CStr but I guess that's a bigger conversation.

@strohel what do you think?

dst.add(self.len()).write(0); // Null terminated.
}
}
Expand Down
Loading