I’m still seeing bad transmutes. fn from_str<'a>(s: &'a str) -> RawIobuf<'a> { unsafe { let bytes: &mut [u8] = mem::transmute(s.as_bytes()); RawIobuf::of_buf(BorrowedBuffer(bytes)) } }
This is taking a `&str`, converting to `&[u8]`, and then transmuting to `&mut [u8]`. Besides being undefined, I have to assume it's also possible for other code later on to end up attempting to actually mutate this data, which will either a) be really bad, or b) not even be possible if it's a string constant in read-only member. -Kevin > On Sep 4, 2014, at 1:15 AM, Clark Gaebel <cg.wowus...@gmail.com> wrote: > > I think you’re right! Thanks for pointing at UnsafeCell. That seems like > exactly what I want. It has been fixed. > > Thanks a ton for the catch! > - Clark > > > On Thu, Sep 4, 2014 at 12:46 AM, Vladimir Matveev <dpx.infin...@gmail.com> > wrote: > > Hi! > > I’ve noticed this piece of code in your library: > > #[inline] > fn as_mut_slice(&self) -> &mut [u8] { > unsafe { > match self { > &OwnedBuffer(ref v) => { > let mut_v: &mut Vec<u8> = mem::transmute(v); > mut_v.as_mut_slice() > }, > &BorrowedBuffer(ref s) => { > let mut_s: &mut &mut [u8] = mem::transmute(s); > mut_s.as_mut_slice() > }, > } > } > } > > I was under impression that transmuting & to &mut is undefined behavior in > Rust, and you need to use RefCell (or UnsafeCell) for this. Am I wrong? > > On 04 сент. 2014 г., at 9:17, Clark Gaebel <cg.wowus...@gmail.com> wrote: > > > Hey everyone! > > > > Have you ever needed to communicate with the outside world from a rust > > application? Do you need to send data through a network interface, or touch > > a disk? Then you need Iobufs! > > > > An Iobuf is a nifty abstraction over an array of bytes, which makes writing > > things like highly efficient zero-copy speculative network protocol parsers > > easy! Any time I need to do I/O, I reach for an Iobuf to do the heavy > > lifting. > > > > https://github.com/cgaebel/iobuf > > > > Enjoy, > > - Clark > > _______________________________________________ > > Rust-dev mailing list > > Rust-dev@mozilla.org > > https://mail.mozilla.org/listinfo/rust-dev > > > > _______________________________________________ > Rust-dev mailing list > Rust-dev@mozilla.org > https://mail.mozilla.org/listinfo/rust-dev
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev