Fix NLPacket::create

This commit is contained in:
Atlante45 2015-07-09 13:12:21 -07:00
parent f90f3a05be
commit 01f1a6e2b9

View file

@ -29,11 +29,17 @@ qint64 NLPacket::localHeaderSize() const {
return localHeaderSize(_type);
}
std::unique_ptr<NLPacket> NLPacket::create(PacketType::Value type, int64_t size) {
if (size > maxPayloadSize(type)) {
return std::unique_ptr<NLPacket>();
std::unique_ptr<NLPacket> NLPacket::create(PacketType::Value type, qint64 size) {
auto maxPayload = maxPayloadSize(type);
if (size == -1) {
// default size of -1, means biggest packet possible
size = maxPayload;
}
// Fail with invalid size
Q_ASSERT(size >= 0 || size < maxPayload);
// allocate memory
return std::unique_ptr<NLPacket>(new NLPacket(type, size));
}