Fix handling memory of max size on 32-bit systems: check for size_t overflow #808
Fix handling memory of max size on 32-bit systems: check for size_t overflow #808
Conversation
Codecov Report
@@ Coverage Diff @@
## only-memory-size-helper #808 +/- ##
===========================================================
- Coverage 99.02% 99.00% -0.03%
===========================================================
Files 81 81
Lines 12825 12845 +20
===========================================================
+ Hits 12700 12717 +17
- Misses 125 128 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
|
267ddc0 to
20cb1a0
Compare
bedb050 to
85cf7a8
Compare
| typename = | ||
| typename std::enable_if_t<std::is_integral_v<TypeFrom> && std::is_integral_v<TypeTo> && | ||
| sizeof(TypeFrom) >= sizeof(TypeTo)>> | ||
| inline constexpr bool can_narrow_cast(TypeFrom value) noexcept |
There was a problem hiding this comment.
This is not about limits anymore, move to a new header?
85cf7a8 to
7fb9138
Compare
| return static_cast<uint32_t>(-1); | ||
| #pragma clang diagnostic pop | ||
| } | ||
| if (!can_narrow_cast<size_t>(new_bytes)) |
There was a problem hiding this comment.
The GSL introduced narrow_cast and narrow. The narrow throws exception if conversion changes value. The narrow_cast is just an alias for static_cast so it always succeeds. So probably better name would be can_narrow or can_safely_narrow.
9bfd43e to
e9877d8
Compare
chfast
left a comment
There was a problem hiding this comment.
Clean up git history before merge.
It may fail only on 32-bit systems.
e9877d8 to
c5b89ec
Compare
Alternative to #807