From 1d22b1ae639388ceb82dcb3b23d476295795a7fb Mon Sep 17 00:00:00 2001 From: X512 Date: Mon, 8 Jun 2020 18:13:00 +0900 Subject: [PATCH] PicturePlayer: use BStackOrHeapArray Change-Id: I7908d8304276d14782bde5c2b8c089f3ca0138e2 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2894 Reviewed-by: waddlesplash --- src/kits/interface/PicturePlayer.cpp | 31 +++++++--------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/src/kits/interface/PicturePlayer.cpp b/src/kits/interface/PicturePlayer.cpp index bf2a2c9788..0e893f89a7 100644 --- a/src/kits/interface/PicturePlayer.cpp +++ b/src/kits/interface/PicturePlayer.cpp @@ -21,6 +21,8 @@ #include #include +#include + using BPrivate::PicturePlayer; @@ -116,24 +118,15 @@ draw_polygon(void* _context, size_t numPoints, const BPoint _points[], { adapter_context* context = reinterpret_cast(_context); - // This is rather ugly but works for such a trivial class. - const size_t kMaxStackCount = 200; - char stackData[kMaxStackCount * sizeof(BPoint)]; - BPoint* points = (BPoint*)stackData; - if (numPoints > kMaxStackCount) { - points = (BPoint*)malloc(numPoints * sizeof(BPoint)); - if (points == NULL) - return; - } + BStackOrHeapArray points(numPoints); + if (!points.IsValid()) + return; memcpy((void*)points, _points, numPoints * sizeof(BPoint)); ((void (*)(void*, int32, BPoint*, bool)) context->function_table[fill ? 14 : 13])(context->user_data, numPoints, points, isClosed); - - if (numPoints > kMaxStackCount) - free(points); } @@ -196,22 +189,14 @@ set_clipping_rects(void* _context, size_t numRects, const BRect _rects[]) adapter_context* context = reinterpret_cast(_context); // This is rather ugly but works for such a trivial class. - const size_t kMaxStackCount = 100; - char stackData[kMaxStackCount * sizeof(BRect)]; - BRect* rects = (BRect*)stackData; - if (numRects > kMaxStackCount) { - rects = (BRect*)malloc(numRects * sizeof(BRect)); - if (rects == NULL) - return; - } + BStackOrHeapArray rects(numRects); + if (!rects.IsValid()) + return; memcpy((void*)rects, _rects, numRects * sizeof(BRect)); ((void (*)(void*, BRect*, uint32))context->function_table[20])( context->user_data, rects, numRects); - - if (numRects > kMaxStackCount) - free(rects); }