Fix invalid count for entityMaps

Improve error reporting on failed deserializations
Fixes #2328

This was SVN commit r14806.
This commit is contained in:
sanderd17 2014-03-05 14:58:17 +00:00
parent 02024370d8
commit f3714a7075
2 changed files with 17 additions and 10 deletions

View File

@ -33,7 +33,7 @@ void IDeserializer::NumberU8(const char* name, uint8_t& out, uint8_t lower, uint
Get(name, (u8*)&value, sizeof(uint8_t));
if (!(lower <= value && value <= upper))
throw PSERROR_Deserialize_OutOfBounds();
throw PSERROR_Deserialize_OutOfBounds(name);
out = value;
}
@ -44,7 +44,7 @@ void IDeserializer::NumberI8(const char* name, int8_t& out, int8_t lower, int8_t
Get(name, (u8*)&value, sizeof(uint8_t));
if (!(lower <= value && value <= upper))
throw PSERROR_Deserialize_OutOfBounds();
throw PSERROR_Deserialize_OutOfBounds(name);
out = value;
}
@ -56,7 +56,7 @@ void IDeserializer::NumberU16(const char* name, uint16_t& out, uint16_t lower, u
value = to_le16(value);
if (!(lower <= value && value <= upper))
throw PSERROR_Deserialize_OutOfBounds();
throw PSERROR_Deserialize_OutOfBounds(name);
out = value;
}
@ -68,7 +68,7 @@ void IDeserializer::NumberI16(const char* name, int16_t& out, int16_t lower, int
value = (i16)to_le16((u16)value);
if (!(lower <= value && value <= upper))
throw PSERROR_Deserialize_OutOfBounds();
throw PSERROR_Deserialize_OutOfBounds(name);
out = value;
}
@ -80,7 +80,7 @@ void IDeserializer::NumberU32(const char* name, uint32_t& out, uint32_t lower, u
value = to_le32(value);
if (!(lower <= value && value <= upper))
throw PSERROR_Deserialize_OutOfBounds();
throw PSERROR_Deserialize_OutOfBounds(name);
out = value;
}
@ -92,7 +92,7 @@ void IDeserializer::NumberI32(const char* name, int32_t& out, int32_t lower, int
value = (i32)to_le32((u32)value);
if (!(lower <= value && value <= upper))
throw PSERROR_Deserialize_OutOfBounds();
throw PSERROR_Deserialize_OutOfBounds(name);
out = value;
}
@ -189,7 +189,7 @@ void IDeserializer::String(const char* name, std::wstring& out, uint32_t minleng
throw PSERROR_Deserialize_InvalidCharInString();
if (!(minlength <= out.length() && out.length() <= maxlength))
throw PSERROR_Deserialize_OutOfBounds();
throw PSERROR_Deserialize_OutOfBounds(name);
}
void IDeserializer::RawBytes(const char* name, u8* data, size_t len)

View File

@ -22,8 +22,7 @@
/**
* A fast replacement for map<entity_id_t, T>.
* We make the following assumptions:
* - entity id's (keys) are unique and are inserted in increasing order
* - an entity id that was removed is never added again
* - entity id's (keys) are unique
* - modifications (add / delete) are far less frequent then look-ups
* - preformance for iteration is important
*/
@ -149,6 +148,7 @@ fill_gaps:
}
value_type& item = m_Buffer[key];
key_type oldKey = item.first;
item.first = key;
if (key == m_BufferSize) // push_back
{
@ -164,6 +164,8 @@ fill_gaps:
}
else // set existing value
{
if (oldKey == INVALID_ENTITY)
m_Count++;
item.second = value; // overwrite existing
}
}
@ -247,11 +249,16 @@ struct SerializeEntityMap
{
size_t len = value.size();
serialize.NumberU32_Unbounded("length", (u32)len);
size_t count = 0;
for (typename EntityMap<V>::iterator it = value.begin(); it != value.end(); ++it)
{
serialize.NumberI32_Unbounded("key", it->first);
serialize.NumberU32_Unbounded("key", it->first);
VSerializer()(serialize, "value", it->second);
count++;
}
// test to see if the entityMap count wasn't wrong
// (which causes a crashing deserialisation)
ENSURE(count == len);
}
template<class V>