Fix infinite loop with error in lsort -unique

Reported-by: Sergei Gavrikov <sergei.gavrikov@gmail.com>
Signed-off-by: Steve Bennett <steveb@workware.net.au>