Patchwork D8019: rust-node: avoid meaningless read at the end of odd prefix

login
register
mail settings
Submitter phabricator
Date Jan. 27, 2020, 7:35 p.m.
Message ID <differential-rev-PHID-DREV-co6yqvugqh7edb2bnwek-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/44701/
State Superseded
Headers show

Comments

phabricator - Jan. 27, 2020, 7:35 p.m.
gracinet created this revision.
Herald added subscribers: mercurial-devel, kevincox.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This should be heavily factored out by the CPU branch predictor
  anyway.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8019

AFFECTED FILES
  rust/hg-core/src/revlog/node.rs

CHANGE DETAILS




To: gracinet, #hg-reviewers
Cc: kevincox, mercurial-devel

Patch

diff --git a/rust/hg-core/src/revlog/node.rs b/rust/hg-core/src/revlog/node.rs
--- a/rust/hg-core/src/revlog/node.rs
+++ b/rust/hg-core/src/revlog/node.rs
@@ -223,6 +223,7 @@ 
     /// This is also the `i`th hexadecimal digit in numeric form,
     /// also called a [nybble](https://en.wikipedia.org/wiki/Nibble).
     pub fn get_nybble(&self, i: usize) -> u8 {
+        assert!(i < self.len());
         get_nybble(self.buf, i)
     }
 }