fix empty buffer under some circumstances