summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorljfa-ag <ljfa-ag@web.de>2015-09-05 13:17:56 +0200
committerljfa-ag <ljfa-ag@web.de>2015-09-05 13:17:56 +0200
commit3b7d44aa0b84f9c208d906f4d10517e36220ee80 (patch)
tree3d20d738d7b45ec34c4abd47baef17d06564e879
parentfd32c7c7d05bc7e823d7e129d16193be4635b0c7 (diff)
downloadProject-Tick-3b7d44aa0b84f9c208d906f4d10517e36220ee80.tar.gz
Project-Tick-3b7d44aa0b84f9c208d906f4d10517e36220ee80.zip
Create constant for maximum list and array length
-rw-r--r--include/io/stream_writer.h4
-rw-r--r--src/tag_array.cpp4
-rw-r--r--src/tag_list.cpp2
3 files changed, 6 insertions, 4 deletions
diff --git a/include/io/stream_writer.h b/include/io/stream_writer.h
index c771426bb3..959202e1ad 100644
--- a/include/io/stream_writer.h
+++ b/include/io/stream_writer.h
@@ -54,8 +54,10 @@ void write_tag(const std::string& key, const tag& t, std::ostream& os, endian::e
class stream_writer
{
public:
- ///Maximum length of an NBT string (65535)
+ ///Maximum length of an NBT string (16 bit unsigned)
static constexpr size_t max_string_len = UINT16_MAX;
+ ///Maximum length of an NBT list or array (32 bit signed)
+ static constexpr uint32_t max_array_len = INT32_MAX;
/**
* @param os the stream to write to
diff --git a/src/tag_array.cpp b/src/tag_array.cpp
index 8bb8bf72e4..99e32549b7 100644
--- a/src/tag_array.cpp
+++ b/src/tag_array.cpp
@@ -81,7 +81,7 @@ void tag_array<int32_t>::read_payload(io::stream_reader& reader)
template<>
void tag_array<int8_t>::write_payload(io::stream_writer& writer) const
{
- if(size() > INT32_MAX)
+ if(size() > io::stream_writer::max_array_len)
{
writer.get_ostr().setstate(std::ios::failbit);
throw std::length_error("Byte array is too large for NBT");
@@ -93,7 +93,7 @@ void tag_array<int8_t>::write_payload(io::stream_writer& writer) const
template<>
void tag_array<int32_t>::write_payload(io::stream_writer& writer) const
{
- if(size() > INT32_MAX)
+ if(size() > io::stream_writer::max_array_len)
{
writer.get_ostr().setstate(std::ios::failbit);
throw std::length_error("Int array is too large for NBT");
diff --git a/src/tag_list.cpp b/src/tag_list.cpp
index 039bd9b77a..67a3d4c15f 100644
--- a/src/tag_list.cpp
+++ b/src/tag_list.cpp
@@ -116,7 +116,7 @@ void tag_list::read_payload(io::stream_reader& reader)
void tag_list::write_payload(io::stream_writer& writer) const
{
- if(size() > INT32_MAX)
+ if(size() > io::stream_writer::max_array_len)
{
writer.get_ostr().setstate(std::ios::failbit);
throw std::length_error("List is too large for NBT");