Patchwork D12532: rust-dirstatemap: use a checked sub instead of a potentially underflowing one

login
register
mail settings
Submitter phabricator
Date April 12, 2022, 4:05 p.m.
Message ID <differential-rev-PHID-DREV-mm7gf7ov7rsosynizshd-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50880/
State New
Headers show

Comments

phabricator - April 12, 2022, 4:05 p.m.
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This was missed in 2593873cda0f <https://phab.mercurial-scm.org/rHG2593873cda0f41fdf8e905b49a5a763d9a67788f>

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/hg-core/src/dirstate_tree/dirstate_map.rs

CHANGE DETAILS




To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
@@ -1337,7 +1337,9 @@ 
             )?
             .and_then(|node| {
                 if let Some(source) = &node.copy_source {
-                    *count -= 1;
+                    *count = count
+                        .checked_sub(1)
+                        .expect("nodes_with_copy_source_count should be >= 0");
                     DirstateMap::count_dropped_path(unreachable_bytes, source);
                 }
                 node.copy_source.take().map(Cow::into_owned)