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

Conversation

dmikushin
Copy link

Hi, thanks for your hard work on cameleon, this is a great project!

This trivial PR fixes an error occured during my compilation, possibly with a newer version of Rust compiler:

245 |                 std::ptr::copy_nonoverlapping(self.as_ptr().cast::<i8>(), dst, self.len());
    |                 -----------------------------                             ^^^ expected `*mut i8`, found `*mut u8`
    |                 |
    |                 arguments to this function are incorrect

Changelog

  • Using a proper type casting from *mut u8 to *mut i8 in std::ptr::copy_nonoverlapping.

245 |                 std::ptr::copy_nonoverlapping(self.as_ptr().cast::<i8>(), dst, self.len());
    |                 -----------------------------                             ^^^ expected `*mut i8`, found `*mut u8`
    |                 |
    |                 arguments to this function are incorrect
@@ -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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants