From 6d0c43dbf085ba6611cd82c705f126d01ad48b5e Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 19 Apr 2024 18:32:49 +0200 Subject: [PATCH] Fix error found by static analysis tools. --- .../gles_common/rasterizer_canvas_batcher.h | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/drivers/gles_common/rasterizer_canvas_batcher.h b/drivers/gles_common/rasterizer_canvas_batcher.h index 6cc2e1d79..885658aaa 100644 --- a/drivers/gles_common/rasterizer_canvas_batcher.h +++ b/drivers/gles_common/rasterizer_canvas_batcher.h @@ -3247,21 +3247,45 @@ PREAMBLE(bool)::_sort_items_match(const BSortItem &p_a, const BSortItem &p_b) co // if (a->commands.size() != 1) // return false; + + // p_a's type is already checked outside to be these + //const RasterizerCanvas::Item::Command &cb = *b->commands[0]; + //if ((cb.type != RasterizerCanvas::Item::Command::TYPE_RECT) && (cb.type != RasterizerCanvas::Item::Command::TYPE_MULTIRECT) && (cb.type != RasterizerCanvas::Item::Command::TYPE_RECT_ANIMATION)) { + // return false; + //} + + const RasterizerCanvas::Item::Command &ca = *a->commands[0]; const RasterizerCanvas::Item::Command &cb = *b->commands[0]; - if ((cb.type != RasterizerCanvas::Item::Command::TYPE_RECT) && (cb.type != RasterizerCanvas::Item::Command::TYPE_MULTIRECT) && (cb.type != RasterizerCanvas::Item::Command::TYPE_RECT_ANIMATION)) { + + if ((ca.type != cb.type)) { return false; } - const RasterizerCanvas::Item::Command &ca = *a->commands[0]; // tested outside function - // if (ca.type != Item::Command::TYPE_RECT) + // if (ca.type != Item::Command::TYPE_RECT || ...) // return false; - const RasterizerCanvas::Item::CommandRect *rect_a = static_cast(&ca); - const RasterizerCanvas::Item::CommandRect *rect_b = static_cast(&cb); - - if (rect_a->texture != rect_b->texture) { - return false; + if (ca.type == RasterizerCanvas::Item::Command::TYPE_RECT) { + const RasterizerCanvas::Item::CommandRect *rect_a = static_cast(&ca); + const RasterizerCanvas::Item::CommandRect *rect_b = static_cast(&cb); + + if (rect_a->texture != rect_b->texture) { + return false; + } + } else if (ca.type == RasterizerCanvas::Item::Command::TYPE_MULTIRECT) { + const RasterizerCanvas::Item::CommandMultiRect *rect_a = static_cast(&ca); + const RasterizerCanvas::Item::CommandMultiRect *rect_b = static_cast(&cb); + + if (rect_a->texture != rect_b->texture) { + return false; + } + } else if (ca.type == RasterizerCanvas::Item::Command::TYPE_RECT_ANIMATION) { + const RasterizerCanvas::Item::CommandRectAnimation *rect_a = static_cast(&ca); + const RasterizerCanvas::Item::CommandRectAnimation *rect_b = static_cast(&cb); + + if (rect_a->get_command_rect()->texture != rect_b->get_command_rect()->texture) { + return false; + } } /* ALTERNATIVE APPROACH NOT LIMITED TO RECTS