From 5be3335436501c5e0d3f5cb047edba1371aeb187 Mon Sep 17 00:00:00 2001 From: Harald Fernengel Date: Tue, 2 Jun 2009 15:02:00 +0200 Subject: Use a QVarLengthArray instead of some hacky self-made container This won't leak on error case, and will work with arbitrary sizes. Also changed from int to short as instructed by Samuel. Reviewed-by: Samuel --- src/gui/painting/qpaintengine_raster.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 847904b..58ffb02 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -3876,11 +3876,7 @@ static void qt_merge_clip(const QClipData *c1, const QClipData *c2, QClipData *r { Q_ASSERT(c1->clipSpanHeight == c2->clipSpanHeight && c1->clipSpanHeight == result->clipSpanHeight); - // ### buffer overflow possible - const int BUFFER_SIZE = 4096; - int buffer[BUFFER_SIZE]; - int *b = buffer; - int bsize = BUFFER_SIZE; + QVarLengthArray buffer; QClipData::ClipLine *c1ClipLines = const_cast(c1)->clipLines(); QClipData::ClipLine *c2ClipLines = const_cast(c2)->clipLines(); @@ -3907,11 +3903,8 @@ static void qt_merge_clip(const QClipData *c1, const QClipData *c2, QClipData *r // find required length int max = qMax(c1_spans[c1_count - 1].x + c1_spans[c1_count - 1].len, c2_spans[c2_count - 1].x + c2_spans[c2_count - 1].len); - if (max > bsize) { - b = (int *)realloc(bsize == BUFFER_SIZE ? 0 : b, max*sizeof(int)); - bsize = max; - } - memset(buffer, 0, BUFFER_SIZE * sizeof(int)); + buffer.resize(max); + memset(buffer.data(), 0, buffer.size() * sizeof(short)); // Fill with old spans. for (int i = 0; i < c1_count; ++i) { @@ -3947,8 +3940,6 @@ static void qt_merge_clip(const QClipData *c1, const QClipData *c2, QClipData *r result->appendSpan(sx, x - sx, y, coverage); } } - if (b != buffer) - free(b); } void QRasterPaintEnginePrivate::initializeRasterizer(QSpanData *data) -- cgit v0.12