Skip to content

Commit c2d7f74

Browse files
Copilotnunoplopes
andauthored
Replace offset(1) pointer increments with += 1
Agent-Logs-Url: https://github.com/Cpp2Rust/cpp2rust/sessions/4292d6f5-f28a-4fb3-9f45-3a67ee6f91c7 Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
1 parent 759011e commit c2d7f74

6 files changed

Lines changed: 11 additions & 11 deletions

File tree

libcc2rs/src/inc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<T> UnsafePostfixInc for *const T {
8787
#[inline]
8888
unsafe fn postfix_inc(&mut self) -> Self {
8989
let copy = *self;
90-
*self = self.offset(1);
90+
*self += 1;
9191
copy
9292
}
9393
}
@@ -96,7 +96,7 @@ impl<T> UnsafePostfixInc for *mut T {
9696
#[inline]
9797
unsafe fn postfix_inc(&mut self) -> Self {
9898
let copy = *self;
99-
*self = self.offset(1);
99+
*self += 1;
100100
copy
101101
}
102102
}
@@ -111,15 +111,15 @@ pub trait UnsafePrefixInc {
111111
impl<T> UnsafePrefixInc for *const T {
112112
#[inline]
113113
unsafe fn prefix_inc(&mut self) -> Self {
114-
*self = self.offset(1);
114+
*self += 1;
115115
*self
116116
}
117117
}
118118

119119
impl<T> UnsafePrefixInc for *mut T {
120120
#[inline]
121121
unsafe fn prefix_inc(&mut self) -> Self {
122-
*self = self.offset(1);
122+
*self += 1;
123123
*self
124124
}
125125
}

libcc2rs/src/io.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub fn fread_refcount(a0: AnyPtr, a1: u64, a2: u64, a3: Ptr<::std::fs::File>) ->
112112

113113
for &byte in &buffer[..n] {
114114
dst.write(byte);
115-
dst = dst.offset(1);
115+
dst += 1;
116116
}
117117

118118
read_bytes += n;
@@ -154,7 +154,7 @@ pub unsafe fn fread_unsafe(
154154
for &byte in &buffer[..n] {
155155
unsafe {
156156
*dst = byte;
157-
dst = dst.offset(1);
157+
dst += 1;
158158
}
159159
}
160160

libcc2rs/src/rc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ impl<T> Iterator for StringIterator<T> {
641641
// skip the null terminator
642642
if self.ptr.get_offset() + 1 < self.ptr.len() {
643643
let value = self.ptr.clone();
644-
self.ptr = self.ptr.offset(1);
644+
self.ptr += 1;
645645
Some(value)
646646
} else {
647647
None

rules/algorithm/tgt_unsafe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ unsafe fn f2<T1: Clone, T2: From<T1>>(a0: *const T1, a1: *const T1, a2: *mut T2)
1313
let mut curr = a0.clone();
1414
while curr < a1 {
1515
*outptr = (*curr).clone().into();
16-
curr = curr.offset(1);
17-
outptr = outptr.offset(1);
16+
curr += 1;
17+
outptr += 1;
1818
}
1919
outptr
2020
}

rules/stdio/tgt_refcount.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn f6(a0: AnyPtr, a1: u64, a2: u64, a3: Ptr<::std::fs::File>) -> u64 {
8080

8181
for i in 0..to_fill {
8282
buffer[i] = src.read();
83-
src = src.offset(1);
83+
src += 1;
8484
}
8585

8686
let mut off = 0;

rules/stdio/tgt_unsafe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ unsafe fn f6(a0: *const ::libc::c_void, a1: u64, a2: u64, a3: *mut ::std::fs::Fi
8585

8686
for i in 0..to_fill {
8787
buffer[i] = *src;
88-
src = src.offset(1);
88+
src += 1;
8989
}
9090

9191
let mut off = 0;

0 commit comments

Comments
 (0)