From 86a0e70d65f406359e36b1a0f714a8ff3e5394e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Tue, 25 Apr 2023 14:30:44 +0200 Subject: [PATCH] QDataBuffer: decrease size on shrink() Having the size potentially be larger than the capacity can't be considered anything other than a bug. Pick-to: 6.5 Change-Id: Id059c0f2c7320f992d897011d7aa944c5cb86058 Reviewed-by: Laszlo Agocs --- src/gui/painting/qdatabuffer_p.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/gui/painting/qdatabuffer_p.h b/src/gui/painting/qdatabuffer_p.h index 1e62c8d924..8f467afe4e 100644 --- a/src/gui/painting/qdatabuffer_p.h +++ b/src/gui/painting/qdatabuffer_p.h @@ -89,13 +89,16 @@ public: } void shrink(qsizetype size) { + Q_ASSERT(capacity >= size); capacity = size; if (size) { buffer = (Type*) realloc(static_cast(buffer), capacity * sizeof(Type)); Q_CHECK_PTR(buffer); + siz = std::min(siz, size); } else { free(buffer); buffer = nullptr; + siz = 0; } }