fdo#74042 Don't attempt to copy more than a string has to offer

Change-Id: I5898efeaecce2cf2ee7d4ac581a21761533138bd
Reviewed-on: https://gerrit.libreoffice.org/7698
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>