Skip to content

Commit 2573742

Browse files
committed
remove/tweak some no-panic code
rust-lang/rust#99223 fixes the bounds check in split_mut and splitn_mut, so no need to carry those custom implementations anymore. Also tweak some of the bounds checking code in the target.xml handler, since it re-introduced a bounds check in newer rustc versions...
1 parent cc03eb2 commit 2573742

File tree

12 files changed

+14
-143
lines changed

12 files changed

+14
-143
lines changed

src/protocol/commands.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub(self) mod prelude {
1212
pub use crate::protocol::commands::ParseCommand;
1313
pub use crate::protocol::common::hex::{decode_hex, decode_hex_buf};
1414
pub use crate::protocol::packet::PacketBuf;
15-
pub use crate::util::no_panic_iter::SliceExt;
1615
}
1716

1817
pub trait ParseCommand<'a>: Sized {

src/protocol/commands/_m.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl<'a> ParseCommand<'a> for m<'a> {
3232
let (buf, body_range) = buf.into_raw_buf();
3333
let body = buf.get_mut(body_range.start..body_range.end)?;
3434

35-
let mut body = body.split_mut_no_panic(|b| *b == b',');
35+
let mut body = body.split_mut(|b| *b == b',');
3636

3737
let addr = decode_hex_buf(body.next()?).ok()?;
3838
let addr_len = addr.len();

src/protocol/commands/_m_upcase.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl<'a> ParseCommand<'a> for M<'a> {
1212
fn from_packet(buf: PacketBuf<'a>) -> Option<Self> {
1313
let body = buf.into_body();
1414

15-
let mut body = body.split_mut_no_panic(|&b| b == b',' || b == b':');
15+
let mut body = body.split_mut(|&b| b == b',' || b == b':');
1616
let addr = decode_hex_buf(body.next()?).ok()?;
1717
let len = decode_hex(body.next()?).ok()?;
1818
let val = decode_hex_buf(body.next()?).ok()?;

src/protocol/commands/_vFile_open.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl<'a> ParseCommand<'a> for vFileOpen<'a> {
1919

2020
match body {
2121
[b':', body @ ..] => {
22-
let mut body = body.splitn_mut_no_panic(3, |b| *b == b',');
22+
let mut body = body.splitn_mut(3, |b| *b == b',');
2323
let filename = decode_hex_buf(body.next()?).ok()?;
2424
let flags = HostIoOpenFlags::from_bits(decode_hex(body.next()?).ok()?)?;
2525
let mode = HostIoOpenMode::from_bits(decode_hex(body.next()?).ok()?)?;

src/protocol/commands/_vFile_pread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl<'a> ParseCommand<'a> for vFilePread<'a> {
2121

2222
match body {
2323
[b':', body @ ..] => {
24-
let mut body = body.splitn_mut_no_panic(3, |b| *b == b',');
24+
let mut body = body.splitn_mut(3, |b| *b == b',');
2525
let fd = decode_hex(body.next()?).ok()?;
2626
let count = decode_hex(body.next()?).ok()?;
2727
let offset = decode_hex(body.next()?).ok()?;

src/protocol/commands/_vFile_pwrite.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl<'a> ParseCommand<'a> for vFilePwrite<'a> {
1919

2020
match body {
2121
[b':', body @ ..] => {
22-
let mut body = body.splitn_mut_no_panic(3, |b| *b == b',');
22+
let mut body = body.splitn_mut(3, |b| *b == b',');
2323
let fd = decode_hex(body.next()?).ok()?;
2424
let offset = decode_hex_buf(body.next()?).ok()?;
2525
let data = decode_bin_buf(body.next()?).ok()?;

src/protocol/commands/_vRun.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl<'a> ParseCommand<'a> for vRun<'a> {
1313
fn from_packet(buf: PacketBuf<'a>) -> Option<Self> {
1414
let body = buf.into_body();
1515

16-
let mut body = body.splitn_mut_no_panic(3, |b| *b == b';');
16+
let mut body = body.splitn_mut(3, |b| *b == b';');
1717

1818
let _first_semi = body.next()?;
1919
let filename = match decode_hex_buf(body.next()?).ok()? {

src/protocol/commands/_x_upcase.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl<'a> ParseCommand<'a> for X<'a> {
1414
fn from_packet(buf: PacketBuf<'a>) -> Option<Self> {
1515
let body = buf.into_body();
1616

17-
let mut body = body.split_mut_no_panic(|&b| b == b',' || b == b':');
17+
let mut body = body.split_mut(|&b| b == b',' || b == b':');
1818
let addr = decode_hex_buf(body.next()?).ok()?;
1919
let len = decode_hex(body.next()?).ok()?;
2020
let val = decode_bin_buf(body.next()?).ok()?;

src/protocol/commands/breakpoint.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::protocol::common::hex::{decode_hex, decode_hex_buf};
2-
use crate::util::no_panic_iter::SliceExt;
32

43
// Breakpoint packets are split up like this:
54
//
@@ -24,7 +23,7 @@ pub struct BasicBreakpoint<'a> {
2423

2524
impl<'a> BasicBreakpoint<'a> {
2625
pub fn from_slice(body: &'a mut [u8]) -> Option<BasicBreakpoint<'a>> {
27-
let mut body = body.splitn_mut_no_panic(4, |b| matches!(*b, b',' | b';'));
26+
let mut body = body.splitn_mut(4, |b| matches!(*b, b',' | b';'));
2827
let type_ = decode_hex(body.next()?).ok()?;
2928
let addr = decode_hex_buf(body.next()?).ok()?;
3029
let kind = decode_hex_buf(body.next()?).ok()?;
@@ -42,7 +41,7 @@ pub struct BytecodeBreakpoint<'a> {
4241

4342
impl<'a> BytecodeBreakpoint<'a> {
4443
pub fn from_slice(body: &'a mut [u8]) -> Option<BytecodeBreakpoint<'a>> {
45-
let mut body = body.splitn_mut_no_panic(2, |b| *b == b';');
44+
let mut body = body.splitn_mut(2, |b| *b == b';');
4645

4746
let base = BasicBreakpoint::from_slice(body.next()?)?;
4847

src/stub/core_impl/target_xml.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ impl<T: Target, C: Connection> GdbStubImpl<T, C> {
3030
let xml_len = xml.len();
3131

3232
let start = xml_len.min(cmd.offset as usize);
33-
let end = xml_len.min(cmd.offset as usize + cmd.length);
33+
let end = xml_len.min((cmd.offset as usize).saturating_add(cmd.length));
3434

35-
// LLVM isn't smart enough to realize that `end` will always be greater than
36-
// `start`, and fails to elide the `slice_index_order_fail` check unless we
37-
// include this seemingly useless call to `max`.
38-
let data = &xml[start..end.max(start)];
35+
// LLVM isn't smart enough to realize that `start <= end`, and fails to elide a
36+
// `slice_end_index_len_fail` check unless we include this seemingly useless
37+
// call to `min`.
38+
let data = &xml[start.min(end)..end];
3939

4040
let n = data.len().min(cmd.buf.len());
4141
cmd.buf[..n].copy_from_slice(&data[..n]);

0 commit comments

Comments
 (0)