@@ -38,7 +38,10 @@ typename std::enable_if<!std::is_same_v<Container, std::ifstream>, bool>::type
38
38
from_bytes (std::basic_string<CharType> &value, Container &bytes,
39
39
std::size_t ¤t_index, std::size_t &end_index,
40
40
std::error_code &error_code) {
41
-
41
+ // clear out the value - this ensures that value will be only what is read
42
+ // from the stream, and not any previous data that may have been set during
43
+ // the construction of the containing object T().
44
+ value.clear ();
42
45
if (current_index >= end_index) {
43
46
// end of input
44
47
// return true for forward compatibility
@@ -75,7 +78,10 @@ typename std::enable_if<std::is_same_v<Container, std::ifstream>, bool>::type
75
78
from_bytes (std::basic_string<CharType> &value, Container &bytes,
76
79
std::size_t ¤t_index, std::size_t &end_index,
77
80
std::error_code &error_code) {
78
-
81
+ // clear out the value - this ensures that value will be only what is read
82
+ // from the stream, and not any previous data that may have been set during
83
+ // the construction of the containing object T().
84
+ value.clear ();
79
85
if (current_index >= end_index) {
80
86
// end of input
81
87
// return true for forward compatibility
@@ -109,4 +115,4 @@ from_bytes(std::basic_string<CharType> &value, Container &bytes,
109
115
} // namespace detail
110
116
111
117
} // namespace alpaca
112
- #endif
118
+ #endif
0 commit comments