Skip to content

Commit de74747

Browse files
committed
Allow system::istream to read remainder into integer if valid.
1 parent af6646e commit de74747

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

include/bitcoin/system/impl/stream/iostream/istream.ipp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace system {
2828

2929
// Allowed here for low level performance benefit.
3030
BC_PUSH_WARNING(NO_POINTER_ARITHMETIC)
31+
BC_PUSH_WARNING(NO_UNSAFE_COPY_N)
3132

3233
template <typename Character>
3334
template <typename Buffer>
@@ -150,18 +151,19 @@ template <typename Character>
150151
void
151152
istream<Character>::read(char_type* data, std::streamsize count) NOEXCEPT
152153
{
153-
const auto bytes = possible_narrow_sign_cast<size_t>(count);
154+
auto bytes = possible_narrow_sign_cast<size_t>(count);
154155

155156
if (is_overflow(bytes))
156157
{
158+
if (state_ != goodbit)
159+
return;
160+
161+
// Allow read to end if state was good (std::istream behavior).
162+
bytes = end_ - position_;
157163
setstate(badbit);
158-
return;
159164
}
160165

161-
BC_PUSH_WARNING(NO_UNSAFE_COPY_N)
162166
std::copy_n(position_, bytes, data);
163-
BC_POP_WARNING()
164-
165167
position_ += bytes;
166168
}
167169

@@ -181,6 +183,7 @@ istream<Character>::is_overflow(pos_type size) const NOEXCEPT
181183
return (state_ != goodbit) || (size > (end_ - position_));
182184
}
183185

186+
BC_POP_WARNING()
184187
BC_POP_WARNING()
185188

186189
} // namespace system

0 commit comments

Comments
 (0)