Check for empty() before calling top().

Else it might crash sometimes.

Change-Id: I6a24fff83c3d36346debae5c0f2b8c0646a15c01
(cherry picked from commit 3f177756dbdb67d901453000c3f11694770d2761)
Reviewed-on: https://gerrit.libreoffice.org/9990
Tested-by: Michael Stahl <mstahl@redhat.com>
Reviewed-by: Michael Stahl <mstahl@redhat.com>