unarr: fix check for infinite loop (fixes issue 2670)