merge-script
b62abc7eec
Merge bitcoin/bitcoin#34436 : refactor: add overflow-safe CeilDiv helper and use it in unsigned callsites
...
02d047fd5b93d96f159db2b8e95fc39450505159 refactor: 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:
ACK 02d047fd5b93d96f159db2b8e95fc39450505159
hodlinator:
ACK 02d047fd5b93d96f159db2b8e95fc39450505159
sedited:
ACK 02d047fd5b93d96f159db2b8e95fc39450505159
Tree-SHA512: b09336031f487e6ce289822e0ffeb8cfc8cfe8a2f4f3f49470748dfbd0a6cbab97498674cb8686dd2bd4ab6dd0b79cfdf2da00041fee12d109892e1bc5dde0ff
2026-03-11 11:30:42 +01:00
..
2026-03-11 10:11:02 +01:00
2026-03-11 11:30:42 +01:00
2026-02-18 21:29:07 +01:00
2026-02-02 19:32:14 +01:00
2025-08-07 09:27:25 +01:00
2026-01-30 11:50:17 +00:00
2026-03-06 01:05:52 +01:00
2026-01-27 13:08:50 +01:00
2026-03-02 22:00:53 +01:00
2026-03-03 17:03:56 +00:00
2026-02-25 23:22:29 -08:00
2026-02-03 11:19:01 +01:00
2026-02-02 17:22:31 +00:00
2025-10-13 12:33:23 +01:00
2026-03-10 15:55:36 -07:00
2026-02-25 17:38:13 +01:00
2026-02-09 15:55:58 -05:00
2026-03-10 10:59:09 +00:00
2026-03-08 14:34:37 +00:00
2026-03-08 14:23:49 +00:00
2026-02-02 15:21:14 +00:00
2026-03-11 11:30:42 +01:00
2026-03-11 11:30:42 +01:00
2026-01-31 10:41:50 +00:00
2026-03-11 11:30:42 +01:00
2026-03-11 10:23:40 +01:00
2026-01-29 14:38:35 +00:00
2026-01-29 14:38:35 +00:00
2026-02-06 08:37:19 +01:00
2025-07-10 11:24:40 +02:00
2025-12-16 22:21:15 +01:00
2025-12-16 22:21:15 +01:00
2025-12-16 22:21:15 +01:00
2026-01-14 23:04:12 +01:00
2026-01-20 23:45:29 +01:00
2026-01-14 23:04:12 +01:00
2026-02-11 18:18:21 +01:00
2025-09-12 22:28:41 +02:00
2025-12-16 22:21:15 +01:00
2025-12-16 22:21:15 +01:00
2025-05-19 16:40:33 +01:00
2025-06-03 15:13:54 +02:00
2025-03-12 19:46:54 +01:00
2025-06-03 15:13:57 +02:00
2025-06-03 15:13:57 +02:00
2025-06-03 19:56:55 +02:00
2025-03-12 19:46:54 +01:00
2026-01-21 19:40:25 +05:30
2025-06-10 15:14:24 +02:00
2026-03-11 09:12:13 +01:00
2025-06-10 15:14:24 +02:00
2025-06-10 15:14:24 +02:00
2025-12-19 16:56:02 +00:00
2025-06-10 15:14:24 +02:00
2025-12-16 22:21:15 +01:00
2025-06-10 15:14:24 +02:00
2025-10-06 19:41:35 +01:00
2025-12-16 22:21:15 +01:00
2025-06-10 15:14:24 +02:00
2025-12-16 22:21:15 +01:00
2026-01-19 20:20:13 +01:00
2025-12-16 22:21:15 +01:00
2025-12-16 22:21:15 +01:00
2025-12-16 22:21:15 +01:00
2026-01-14 11:38:07 -08:00
2026-02-17 21:40:46 +05:30
2025-12-16 22:21:15 +01:00
2026-01-14 23:04:12 +01:00
2025-06-03 15:13:57 +02:00
2026-01-14 23:04:12 +01:00
2026-02-25 14:36:19 -08:00
2026-02-02 17:22:31 +00:00
2025-11-13 09:33:36 +01:00
2025-12-16 22:21:15 +01:00
2026-03-10 14:09:27 -04:00
2026-02-20 09:27:17 +01:00
2026-02-23 15:56:25 +01:00
2026-02-23 15:56:25 +01:00
2025-12-16 22:21:15 +01:00
2025-03-12 19:46:54 +01:00
2026-02-09 13:32:28 +00:00
2026-01-19 12:57:16 +01:00
2025-12-16 22:21:15 +01:00
2026-02-11 18:18:21 +01:00
2026-02-02 17:22:31 +00:00
2026-02-02 18:42:44 +01:00
2025-12-16 22:21:15 +01:00
2026-01-14 23:04:12 +01:00
2025-12-16 22:21:15 +01:00
2025-12-16 22:21:15 +01:00
2026-02-13 10:52:25 +01:00
2026-02-17 12:55:26 +01:00
2026-02-17 12:55:26 +01:00
2026-02-11 18:18:21 +01:00
2025-12-16 22:21:15 +01:00
2025-03-12 19:46:54 +01:00
2025-03-12 19:46:54 +01:00
2025-11-20 11:34:21 +09:00
2025-11-20 11:34:21 +09:00
2025-12-19 16:56:02 +00:00
2025-12-16 22:21:15 +01:00
2026-02-19 12:41:12 -08:00
2026-01-30 16:17:12 -05:00
2025-12-13 13:43:24 +01:00
2025-12-16 22:21:15 +01:00
2025-12-16 22:21:15 +01:00
2026-03-06 12:07:41 -08:00
2025-12-16 22:21:15 +01:00
2026-02-11 18:18:21 +01:00
2025-12-16 22:21:15 +01:00
2025-10-14 16:25:52 -04:00
2025-09-30 11:06:43 -07:00
2026-02-02 17:22:31 +00:00
2026-02-02 17:22:31 +00:00
2025-12-16 22:21:15 +01:00
2025-12-16 22:21:15 +01:00
2025-12-16 22:21:15 +01:00
2026-02-11 18:18:21 +01:00
2025-12-16 22:21:15 +01:00
2025-11-24 18:48:43 +01:00
2025-11-24 18:48:43 +01:00
2025-12-16 22:21:15 +01:00
2025-12-16 22:21:15 +01:00
2026-02-26 10:33:29 +00:00
2026-02-11 19:46:19 -05:00
2025-12-16 22:21:15 +01:00
2025-12-16 22:21:15 +01:00
2026-03-02 07:47:53 -08:00
2026-02-13 11:17:26 +00:00
2025-10-02 12:53:55 +01:00
2026-01-14 23:04:12 +01:00
2026-01-22 10:35:14 -05:00
2026-01-23 13:25:42 +01:00
2026-01-20 23:59:41 +01:00
2026-01-20 23:59:41 +01:00
2025-12-16 22:21:15 +01:00
2026-01-14 19:39:01 +01:00
2026-01-14 19:36:14 +01:00
2025-10-02 12:53:55 +01:00
2025-10-02 12:53:55 +01:00
2025-12-16 22:21:15 +01:00
2026-01-14 23:04:12 +01:00
2026-03-04 15:06:34 +01:00
2026-02-11 19:46:12 -05:00
2026-02-11 19:46:12 -05:00
2025-12-16 22:21:15 +01:00
2025-12-16 22:21:15 +01:00
2026-02-06 07:56:57 +01:00
2026-03-04 15:17:02 +00:00
2025-09-30 11:06:09 -07:00
2025-11-03 14:39:48 +01:00
2026-02-02 17:22:31 +00:00
2026-01-14 23:04:12 +01:00
2025-12-16 22:21:15 +01:00
2025-12-16 22:21:15 +01:00
2026-02-11 18:18:21 +01:00
2025-12-16 22:21:15 +01:00
2025-12-16 22:21:15 +01:00
2025-12-16 22:21:15 +01:00
2025-05-10 03:31:30 +00:00
2026-02-11 18:18:21 +01:00
2026-02-02 17:22:31 +00:00
2025-12-21 10:24:09 +01:00
2025-03-12 19:46:54 +01:00
2025-11-14 01:17:38 +02:00
2026-02-07 23:01:17 +01:00
2026-02-02 17:22:31 +00:00
2026-02-02 17:22:31 +00:00
2025-12-16 22:21:15 +01:00
2026-01-20 15:30:46 +01:00
2025-12-16 22:21:15 +01:00
2026-02-08 08:23:37 +01:00
2026-01-02 16:49:23 -08:00
2026-02-24 10:08:47 -05:00
2026-02-24 10:08:47 -05:00
2026-02-24 10:08:47 -05:00
2026-02-24 10:45:49 -05:00
2025-12-18 22:38:02 +01:00
2025-12-30 12:12:26 -08:00
2025-12-16 22:21:15 +01:00
2025-11-03 14:39:48 +01:00
2025-12-16 22:21:15 +01:00
2026-03-06 08:22:42 -08:00
2026-03-06 08:22:42 -08:00
2026-02-02 17:22:31 +00:00
2025-12-12 06:49:59 -04:00
2025-12-16 22:21:15 +01:00
2025-12-19 16:56:02 +00:00
2025-12-16 22:21:15 +01:00
2025-12-16 22:21:15 +01:00