fix buf write error