From 07aa91221fb436d5c3fb8cbc72428b85714c576a Mon Sep 17 00:00:00 2001 From: Robert Loehning Date: Thu, 29 Oct 2020 18:36:52 +0100 Subject: Reduce memory reallocations in QTextTablePrivate::update() This fixes oss-fuzz issue 21100. Task-number: QTBUG-85139 Pick-to: 5.15 Change-Id: I635c1fa9b16dd527e568ec1e98ea7cac73977020 Reviewed-by: Giuseppe D'Angelo Reviewed-by: Lars Knoll --- src/gui/text/qtexttable.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'src/gui/text/qtexttable.cpp') diff --git a/src/gui/text/qtexttable.cpp b/src/gui/text/qtexttable.cpp index d4ed4411bc..951408052d 100644 --- a/src/gui/text/qtexttable.cpp +++ b/src/gui/text/qtexttable.cpp @@ -318,13 +318,6 @@ QTextFrame::iterator QTextTableCell::end() const Destroys the table cell. */ -QTextTablePrivate::~QTextTablePrivate() -{ - if (grid) - free(grid); -} - - QTextTable *QTextTablePrivate::createTable(QTextDocumentPrivate *pieceTable, int pos, int rows, int cols, const QTextTableFormat &tableFormat) { QTextTableFormat fmt = tableFormat; @@ -446,8 +439,7 @@ void QTextTablePrivate::update() const nRows = (cells.size() + nCols-1)/nCols; // qDebug(">>>> QTextTablePrivate::update, nRows=%d, nCols=%d", nRows, nCols); - grid = q_check_ptr((int *)realloc(grid, nRows*nCols*sizeof(int))); - memset(grid, 0, nRows*nCols*sizeof(int)); + grid.assign(nRows * nCols, 0); QTextDocumentPrivate *p = pieceTable; QTextFormatCollection *c = p->formatCollection(); @@ -470,8 +462,7 @@ void QTextTablePrivate::update() const cellIndices[i] = cell; if (r + rowspan > nRows) { - grid = q_check_ptr((int *)realloc(grid, sizeof(int)*(r + rowspan)*nCols)); - memset(grid + (nRows*nCols), 0, sizeof(int)*(r+rowspan-nRows)*nCols); + grid.resize((r + rowspan) * nCols, 0); nRows = r + rowspan; } -- cgit v1.2.3