Skip to content

Commit 9e0c43f

Browse files
committed
fix bug in Ptr subtraction involving mixed (non)reinterpreted case
1 parent e163479 commit 9e0c43f

2 files changed

Lines changed: 17 additions & 15 deletions

File tree

‎libcc2rs/src/rc.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ impl<T> Sub for Ptr<T> {
671671
type Output = usize;
672672
fn sub(self, other: Self) -> Self::Output {
673673
assert!(self.kind == other.kind, "ub: invalid subtraction");
674-
(self.offset - other.offset) / self.elem_step()
674+
(self.offset / self.elem_step()).wrapping_sub(other.offset / other.elem_step())
675675
}
676676
}
677677

‎tests/unit/out/refcount/push_emplace_back.rs‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,15 @@ pub fn push_local_from_field_1(jpg: Ptr<JPEGData>, cond: bool) {
8181
__v.push(Rc::new(RefCell::new(
8282
{
8383
let mut __a0 = (head.as_pointer() as Ptr<u8>).clone();
84-
let __len = (((head.as_pointer() as Ptr<u8>).offset((3) as isize).clone()
85-
as Ptr<u8>)
86-
.get_offset() as isize
87-
- __a0.get_offset() as isize) as usize;
88-
let mut __out = Vec::with_capacity(__len);
84+
let mut __out = Vec::with_capacity(
85+
(head.as_pointer() as Ptr<u8>)
86+
.offset((3) as isize)
87+
.get_offset()
88+
- __a0.get_offset(),
89+
);
8990
while __a0 != (head.as_pointer() as Ptr<u8>).offset((3) as isize) {
90-
__out.push(__a0.read().clone());
91-
__a0.prefix_inc();
91+
__out.push(__a0.read());
92+
__a0 += 1;
9293
}
9394
__out
9495
}
@@ -126,14 +127,15 @@ pub fn emplace_local_from_field_4(jpg: Ptr<JPEGData>, cond: bool) {
126127
.with_mut(|__v: &mut Vec<Value<Vec<u8>>>| {
127128
__v.push(Rc::new(RefCell::new({
128129
let mut __a0 = (head.as_pointer() as Ptr<u8>).clone();
129-
let __len = (((head.as_pointer() as Ptr<u8>).offset((3) as isize).clone()
130-
as Ptr<u8>)
131-
.get_offset() as isize
132-
- __a0.get_offset() as isize) as usize;
133-
let mut __out = Vec::with_capacity(__len);
130+
let mut __out = Vec::with_capacity(
131+
(head.as_pointer() as Ptr<u8>)
132+
.offset((3) as isize)
133+
.get_offset()
134+
- __a0.get_offset(),
135+
);
134136
while __a0 != (head.as_pointer() as Ptr<u8>).offset((3) as isize) {
135-
__out.push(__a0.read().clone());
136-
__a0.prefix_inc();
137+
__out.push(__a0.read());
138+
__a0 += 1;
137139
}
138140
__out
139141
})))

0 commit comments

Comments
 (0)