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

Change-Id: Ifd6acd85a9bf33742cb62327a3b8a4320f35d0f3
(cherry picked from commit 054213e86b8f3b1084474b0447cc7ffaf82178c5)
Reviewed-on: https://gerrit.libreoffice.org/9512
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>