v30.3-roots.1 · Commit 2: [PATCH 02/68] feat(runtime): preserve Roots operator controls on Core 30.3
src/util/byte_units.h
Before: src/util/byte_units.h · After: src/util/byte_units.h
File metadata
index 3d6a9627d88850a5369ce9d1b10289b625b63e82..db498bdae0d1d39831fdcce769ba52253332fc86 100644
Download original patch · Release notes
Diff rows 1–14 of 14. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
src/util/byte_units.h
CHANGED
|
@@ -19,4 +19,14 @@ constexpr size_t operator""_MiB(unsigned long long mebibytes)
|
|
| 19 |
return *bytes;
|
| 20 |
}
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
#endif // BITCOIN_UTIL_BYTE_UNITS_H
|
|
|
|
| 19 |
return *bytes;
|
| 20 |
}
|
| 21 |
|
| 22 |
+
//! Overflow-safe conversion of GiB to bytes.
|
| 23 |
+
constexpr size_t operator""_GiB(unsigned long long gibibytes)
|
| 24 |
+
{
|
| 25 |
+
const auto bytes{CheckedLeftShift(gibibytes, 30)};
|
| 26 |
+
if (!bytes || *bytes > std::numeric_limits<size_t>::max()) {
|
| 27 |
+
throw std::overflow_error("GiB value too large for size_t byte conversion");
|
| 28 |
+
}
|
| 29 |
+
return *bytes;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
#endif // BITCOIN_UTIL_BYTE_UNITS_H
|