fdo#78976: Correct way to determine the end position for matrix check.

Change-Id: Ifd6acd85a9bf33742cb62327a3b8a4320f35d0f3
(cherry picked from commit 054213e86b8f3b1084474b0447cc7ffaf82178c5)