mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-06 21:57:54 +02:00
02d047fd5brefactor: add overflow-safe `CeilDiv` helper (Lőrinc) Pull request description: ### Problem The codebase has many open-coded ceiling-division expressions (for example `(x+y-1)/y`) scattered across files. These are less readable, duplicate logic, and can be overflow-prone in edge cases. ### Fix Introduce a small overflow-safe integer helper, `CeilDiv()`, and use it in existing **unsigned** callsites where the conversion is straightforward and noise-free. ### What this PR does * Adds `CeilDiv()` to `src/util/overflow.h` for unsigned integral inputs. * Keeps the precondition check `assert(divisor > 0)`. * Replaces selected unsigned ceiling-division expressions with `CeilDiv(...)`. * Adds focused unit tests in `src/test/util_tests.cpp` for the migrated patterns. --- This is a pure refactor with no intended behavioral change. Signed arithmetic callsites are intentionally left unchanged in this PR. This PR changed a few more things originally but based on feedback reverted to the simplest cases only. ACKs for top commit: rustaceanrob: ACK02d047fd5bhodlinator: ACK02d047fd5bsedited: ACK02d047fd5bTree-SHA512: b09336031f487e6ce289822e0ffeb8cfc8cfe8a2f4f3f49470748dfbd0a6cbab97498674cb8686dd2bd4ab6dd0b79cfdf2da00041fee12d109892e1bc5dde0ff