Fail in Packet::create if size is invalid

This commit is contained in:
Atlante45 2015-07-09 13:11:43 -07:00
parent e1fc242967
commit f90f3a05be
2 changed files with 3 additions and 5 deletions

View file

@ -14,7 +14,6 @@
#include <iostream>
#include <CoverageMap.h>
#include <NodeData.h>
#include <OctreeConstants.h>

View file

@ -29,10 +29,9 @@ std::unique_ptr<Packet> Packet::create(PacketType::Value type, qint64 size) {
// default size of -1, means biggest packet possible
size = maxPayload;
}
if (size <= 0 || size > maxPayload) {
// Invalid size, return null pointer
return std::unique_ptr<Packet>();
}
// Fail with invalid size
Q_ASSERT(size >= 0 || size < maxPayload);
// allocate memory
return std::unique_ptr<Packet>(new Packet(type, size));