Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1142)

Unified Diff: mojo/public/rust/src/bindings/encoding.rs

Issue 2220183003: Rust: Add validation to decode (Closed) Base URL: git@github.com:domokit/mojo.git@coder-testing
Patch Set: Pass all tests Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/rust/src/bindings/encoding.rs
diff --git a/mojo/public/rust/src/bindings/encoding.rs b/mojo/public/rust/src/bindings/encoding.rs
index 1cb3a91c297d2e6604f1d469352286f66a2b6870..41d9c8ad1983371902ceea4e3c3e58c7743d7f5c 100644
--- a/mojo/public/rust/src/bindings/encoding.rs
+++ b/mojo/public/rust/src/bindings/encoding.rs
@@ -41,6 +41,13 @@ impl Bits {
1 << (self.0 & 7)
}
+ pub fn checked_mul(self, val: usize) -> Option<Bits> {
+ match val.checked_mul(self.0) {
+ Some(result) => Some(Bits(result)),
+ None => None,
+ }
+ }
+
/// Align the bits to some number of bytes.
pub fn align_to_bytes(&mut self, bytes: usize) {
self.0 = util::align_bytes(self.0, 8 * bytes);

Powered by Google App Engine
This is Rietveld 408576698