diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/io/stream_writer.cpp | 1 | ||||
| -rw-r--r-- | src/tag_array.cpp | 6 | ||||
| -rw-r--r-- | src/tag_list.cpp | 6 |
3 files changed, 13 insertions, 0 deletions
diff --git a/src/io/stream_writer.cpp b/src/io/stream_writer.cpp index ee8b0ee2b6..036c5d40ac 100644 --- a/src/io/stream_writer.cpp +++ b/src/io/stream_writer.cpp @@ -41,6 +41,7 @@ void stream_writer::write_string(const std::string& str) { if(str.size() > max_string_len) { + os.setstate(std::ios::failbit); std::ostringstream sstr; sstr << "String is too long for NBT (" << str.size() << " > " << max_string_len << ")"; throw std::length_error(sstr.str()); diff --git a/src/tag_array.cpp b/src/tag_array.cpp index 124c470bd1..41f00eedc3 100644 --- a/src/tag_array.cpp +++ b/src/tag_array.cpp @@ -147,7 +147,10 @@ template<> void tag_array<int8_t>::write_payload(io::stream_writer& writer) const { if(size() > INT32_MAX) + { + writer.get_ostr().setstate(std::ios::failbit); throw std::length_error("Byte array is too large for NBT"); + } writer.write_num(static_cast<int32_t>(size())); writer.get_ostr().write(reinterpret_cast<const char*>(data.data()), data.size()); } @@ -156,7 +159,10 @@ template<> void tag_array<int32_t>::write_payload(io::stream_writer& writer) const { if(size() > INT32_MAX) + { + writer.get_ostr().setstate(std::ios::failbit); throw std::length_error("Int array is too large for NBT"); + } writer.write_num(static_cast<int32_t>(size())); for(int32_t i: data) writer.write_num(i); diff --git a/src/tag_list.cpp b/src/tag_list.cpp index dbdda2db77..d2aa01d314 100644 --- a/src/tag_list.cpp +++ b/src/tag_list.cpp @@ -162,7 +162,10 @@ void tag_list::read_payload(io::stream_reader& reader) void tag_list::write_payload(io::stream_writer& writer) const { if(size() > INT32_MAX) + { + writer.get_ostr().setstate(std::ios::failbit); throw std::length_error("List is too large for NBT"); + } writer.write_type(el_type_ != tag_type::Null ? el_type_ : tag_type::End); @@ -171,7 +174,10 @@ void tag_list::write_payload(io::stream_writer& writer) const { //check if the value is of the correct type if(val.get_type() != el_type_) + { + writer.get_ostr().setstate(std::ios::failbit); throw std::bad_cast(); + } writer.write_payload(val); } } |
