Skip to content
This repository has been archived by the owner on Jun 15, 2024. It is now read-only.

Commit

Permalink
Small followups to tag_long_array addition. Closes #11.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljfa-ag committed May 21, 2018
1 parent dfab039 commit 82366cb
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion include/tag_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace detail
///@endcond

/**
* @brief Tag that contains an array of byte or int values
* @brief Tag that contains an array of byte, int or long values
*
* Common class for tag_byte_array, tag_int_array and tag_long_array.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/tag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static_assert(std::numeric_limits<float>::is_iec559 && std::numeric_limits<doubl

bool is_valid_type(int type, bool allow_end)
{
return (allow_end ? 0 : 1) <= type && type <= 11;
return (allow_end ? 0 : 1) <= type && type <= 12;
}

std::unique_ptr<tag> tag::clone() &&
Expand Down
8 changes: 4 additions & 4 deletions src/tag_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ void tag_array<T>::read_payload(io::stream_reader& reader)
if(length < 0)
reader.get_istr().setstate(std::ios::failbit);
if(!reader.get_istr())
throw io::input_error("Error reading length of generic array tag");
throw io::input_error("Error reading length of array tag");

data.clear();
data.reserve(length);
for(T i = 0; i < length; ++i)
for(int32_t i = 0; i < length; ++i)
{
T val;
reader.read_num(val);
data.push_back(val);
}
if(!reader.get_istr())
throw io::input_error("Error reading contents of generic array tag");
throw io::input_error("Error reading contents of array tag");
}

//Writing
Expand All @@ -84,7 +84,7 @@ void tag_array<T>::write_payload(io::stream_writer& writer) const
if(size() > io::stream_writer::max_array_len)
{
writer.get_ostr().setstate(std::ios::failbit);
throw std::length_error("Generic array is too large for NBT");
throw std::length_error("Array is too large for NBT");
}
writer.write_num(static_cast<int32_t>(size()));
for(T i: data)
Expand Down
4 changes: 2 additions & 2 deletions test/nbttest.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class nbttest : public CxxTest::TestSuite
TS_ASSERT(is_valid_type(1));
TS_ASSERT(is_valid_type(5, false));
TS_ASSERT(is_valid_type(7, true));
TS_ASSERT(is_valid_type(11));
TS_ASSERT(!is_valid_type(12));
TS_ASSERT(is_valid_type(12));
TS_ASSERT(!is_valid_type(13));

//looks like TS_ASSERT_EQUALS can't handle abstract classes...
TS_ASSERT(*tag::create(tag_type::Byte) == tag_byte());
Expand Down
4 changes: 2 additions & 2 deletions test/read_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class read_test : public CxxTest::TestSuite
TS_ASSERT(!is);
is.clear();

//Test for invalid tag type 12
is.str("\x0c");
//Test for invalid tag type 13
is.str("\x0d");
TS_ASSERT_THROWS(reader.read_type(), io::input_error);
TS_ASSERT(!is);
is.clear();
Expand Down

0 comments on commit 82366cb

Please sign in to comment.