Commit 2b096066 authored by Julian Helfferich's avatar Julian Helfferich

Fix Coverty #76265: Make check for array bounds explicit

Before, the function KBlocksField::getCell() checked that the variable
cx was in bounds, i.e. larger than zero and smaller than the width of
the play field. The check that cx is in bounds is important as it is
used to index an array.

Now, the check is done explicitely in KBlocksAIPlanner::process. It is
good practice not to rely too much on a subfunction.
parent 8e1227d4
......@@ -90,7 +90,7 @@ int KBlocksAIPlanner::process(KBlocks_PieceType_Detail pieceValue)
for (int i = 0; i < KBlocksPiece_CellCount; i++) {
int cx = piece.getCellPosX(i);
int cy = piece.getCellPosY(i);
if (mpField->getCell(cx, cy)) {
if (cx < 0 || cx >= w || mpField->getCell(cx, cy)) {
invalidPos = true;
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment