Skip to content

Commit f8c0f11

Browse files
committed
Fix bug in packet.rs
1 parent 0c7ae4d commit f8c0f11

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

framework/src/interface/packet.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ pub fn new_packet_array(count: usize) -> Vec<Packet<NullHeader, EmptyMetadata>>
110110
}
111111
}
112112

113-
114113
impl<T: EndOffset, M: Sized + Send> Packet<T, M> {
115114
// --------------------- Not using packet offsets ------------------------------------------------------
116115
#[inline]
@@ -125,7 +124,6 @@ impl<T: EndOffset, M: Sized + Send> Packet<T, M> {
125124
self.header as *mut u8
126125
}
127126

128-
129127
#[inline]
130128
#[cfg(not(feature = "packet_offset"))]
131129
fn offset(&self) -> usize {
@@ -145,7 +143,6 @@ impl<T: EndOffset, M: Sized + Send> Packet<T, M> {
145143
MBuf::read_metadata_slot(self.mbuf, HEADER_SLOT) as *mut u8
146144
}
147145

148-
149146
#[inline]
150147
#[cfg(feature = "packet_offset")]
151148
fn offset(&self) -> usize {
@@ -309,9 +306,7 @@ impl<T: EndOffset, M: Sized + Send> Packet<T, M> {
309306
let size = header.offset();
310307
let added = (*self.mbuf).add_data_end(size);
311308

312-
let header = self.payload();
313-
314-
let hdr = header as *mut T2;
309+
let hdr = header as *const T2;
315310
let offset = self.offset() + self.payload_offset();
316311
if added >= size {
317312
let dst = if len != offset {
@@ -325,7 +320,7 @@ impl<T: EndOffset, M: Sized + Send> Packet<T, M> {
325320
self.payload() as *mut T2
326321
};
327322
ptr::copy_nonoverlapping(hdr, dst, 1);
328-
Some(create_packet(self.get_mbuf_ref(), hdr, offset))
323+
Some(create_packet(self.get_mbuf_ref(), dst, offset))
329324
} else {
330325
None
331326
}
@@ -396,7 +391,7 @@ impl<T: EndOffset, M: Sized + Send> Packet<T, M> {
396391
#[inline]
397392
pub fn parse_header<T2: EndOffset<PreviousHeader = T>>(mut self) -> Packet<T2, M> {
398393
unsafe {
399-
assert!{self.payload_size() >= T2::size()}
394+
assert!{self.payload_size() > T2::size()}
400395
let hdr = self.payload() as *mut T2;
401396
let offset = self.offset() + self.payload_offset();
402397
create_packet(self.get_mbuf_ref(), hdr, offset)
@@ -406,7 +401,7 @@ impl<T: EndOffset, M: Sized + Send> Packet<T, M> {
406401
#[inline]
407402
pub fn parse_header_and_record<T2: EndOffset<PreviousHeader = T>>(mut self) -> Packet<T2, M> {
408403
unsafe {
409-
assert!{self.payload_size() >= T2::size()}
404+
assert!{self.payload_size() > T2::size()}
410405
let hdr = self.payload() as *mut T2;
411406
let payload_offset = self.payload_offset();
412407
let offset = self.offset() + payload_offset;
@@ -451,7 +446,6 @@ impl<T: EndOffset, M: Sized + Send> Packet<T, M> {
451446
self.pop_offset().map(|offset| self.deparse_header(offset))
452447
}
453448

454-
455449
#[inline]
456450
pub fn reset(mut self) -> Packet<NullHeader, EmptyMetadata> {
457451
unsafe {

0 commit comments

Comments
 (0)