Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit25c169e

Browse files
style: replace manual bounds checks withslice::split_at_checked
1 parent96ef3d8 commit25c169e

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

‎postgres-protocol/src/types/mod.rs‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -639,11 +639,10 @@ impl<'a> FallibleIterator for ArrayValues<'a> {
639639
let val =if len <0{
640640
None
641641
}else{
642-
ifself.buf.len() < lenasusize{
643-
returnErr("invalid value length".into());
644-
}
645-
646-
let(val, buf) =self.buf.split_at(lenasusize);
642+
let(val, buf) =self
643+
.buf
644+
.split_at_checked(lenasusize)
645+
.ok_or("invalid value length")?;
647646
self.buf = buf;
648647
Some(val)
649648
};
@@ -771,10 +770,7 @@ fn read_bound<'a>(
771770
None
772771
}else{
773772
let len = lenasusize;
774-
if buf.len() < len{
775-
returnErr("invalid message size".into());
776-
}
777-
let(value, tail) = buf.split_at(len);
773+
let(value, tail) = buf.split_at_checked(len).ok_or("invalid message size")?;
778774
*buf = tail;
779775
Some(value)
780776
};

‎postgres-types/src/private.rs‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ where
2323
let value =if len <0{
2424
None
2525
}else{
26-
if lenasusize > buf.len(){
27-
returnErr("invalid buffer size".into());
28-
}
29-
let(head, tail) = buf.split_at(lenasusize);
26+
let(head, tail) = buf
27+
.split_at_checked(lenasusize)
28+
.ok_or("invalid buffer size")?;
3029
*buf = tail;
3130
Some(head)
3231
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp