From 0d038be03177c261a1d5ba88a540da76c19d2a9a Mon Sep 17 00:00:00 2001 From: Dale Glass Date: Sun, 5 Jun 2022 13:21:46 +0200 Subject: [PATCH] Fix writing to buffer out of bounds warning --- libraries/entities/src/EntityItemProperties.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 82f50b587a..8461862c4a 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -3977,24 +3977,16 @@ QVector EntityItemProperties::unpackStrokeColors(const QByteArray& strokeC // edit packet sender... bool EntityItemProperties::encodeEraseEntityMessage(const EntityItemID& entityItemID, QByteArray& buffer) { - char* copyAt = buffer.data(); uint16_t numberOfIds = 1; // only one entity ID in this message - int outputLength = 0; - if (buffer.size() < (int)(sizeof(numberOfIds) + NUM_BYTES_RFC4122_UUID)) { qCDebug(entities) << "ERROR - encodeEraseEntityMessage() called with buffer that is too small!"; return false; } - memcpy(copyAt, &numberOfIds, sizeof(numberOfIds)); - copyAt += sizeof(numberOfIds); - outputLength = sizeof(numberOfIds); - - memcpy(copyAt, entityItemID.toRfc4122().constData(), NUM_BYTES_RFC4122_UUID); - outputLength += NUM_BYTES_RFC4122_UUID; - - buffer.resize(outputLength); + buffer.resize(0); + buffer.append(reinterpret_cast(&numberOfIds), sizeof(numberOfIds)); + buffer.append(entityItemID.toRfc4122().constData(), NUM_BYTES_RFC4122_UUID); return true; }