summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorljfa <ljfa-ag@web.de>2015-08-13 14:50:33 +0200
committerljfa <ljfa-ag@web.de>2015-08-13 14:54:34 +0200
commit5e057e152e214d7c92a03192e6c3a235df5961ea (patch)
tree197ecb30d7d93a43e3c1850620052697d500f7f6 /src
parentaac94b91ad83ad8f7832976e6da55d15de6e54e1 (diff)
downloadProject-Tick-5e057e152e214d7c92a03192e6c3a235df5961ea.tar.gz
Project-Tick-5e057e152e214d7c92a03192e6c3a235df5961ea.zip
Set failbit on ostream in case of error
Diffstat (limited to 'src')
-rw-r--r--src/io/stream_writer.cpp1
-rw-r--r--src/tag_array.cpp6
-rw-r--r--src/tag_list.cpp6
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);
}
}