-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
lib/fizzy/limits.hpp
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not about limits anymore, move to a new header?
85cf7a8
to
7fb9138
Compare
lib/fizzy/execute.cpp
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean up git history before merge.
It may fail only on 32-bit systems.
e9877d8
to
c5b89ec
Compare
Alternative to #807