fix writing buffer offset.