diff --git a/libraries/networking/src/NLPacket.cpp b/libraries/networking/src/NLPacket.cpp index 4f17d3d754..711114cc1e 100644 --- a/libraries/networking/src/NLPacket.cpp +++ b/libraries/networking/src/NLPacket.cpp @@ -29,11 +29,17 @@ qint64 NLPacket::localHeaderSize() const { return localHeaderSize(_type); } -std::unique_ptr NLPacket::create(PacketType::Value type, int64_t size) { - if (size > maxPayloadSize(type)) { - return std::unique_ptr(); +std::unique_ptr 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(new NLPacket(type, size)); }