backspace caused undefined behavior is buffer was empty