Page MenuHomePhabricator

util: Add integer left shift helpers
ClosedPublic

Authored by PiRK on Sep 9 2025, 13:50.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABC3577a712c85d: util: Add integer left shift helpers
Summary

The helpers are used in the following commits to increase the safety of
conversions during cache size calculations.

Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
Co-authored-by: stickies-v <stickies-v@protonmail.com>

Notes:

  • This requires some minor adjustments to work with c++17 (see TODO comments)
  • Due to out of orders backports we need to create the overflow.h file.
  • Fuzzers for checked and saturating adds cannot be included here due to these above mentioned out of order backports. They can be added later with 3 additional lines when implemented.

This is a partial backport of core#31483
https://github.com/bitcoin/bitcoin/pull/31483/commits/c03a2795a8e044d17835bbf03de0c64dc7b41da8
https://github.com/bitcoin/bitcoin/pull/31483/commits/d5e2c4a4097c799433cfc5367c61568fad2c784e
Depends on D18579

Test Plan

ninja all check-all bitcoin-fuzzers

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Sep 9 2025, 13:50
Fabien added a subscriber: Fabien.
Fabien added inline comments.
src/test/fuzz/overflow.cpp
27 ↗(On Diff #55532)

review note: std::clamp is c++17

This revision is now accepted and ready to land.Sep 9 2025, 16:40
This revision was automatically updated to reflect the committed changes.