> >> - blen could still be smaller that compressBound(size), you need to > >> recheck > >> - blen could have changed, but you don't take that in account for the > >> following caller. > >> > >> So, I think code has a bug? > > > > Yes, there is a bug, I should consider the case QEMUFile with empty ops. > > The right code should be like: > > > > if (blen < compressBound(size)) { > > if (f->ops->writev_buffer || f->ops->put_buffer) { > > qemu_fflush(f); > > } else { > > return 0; > > } > > } > > .... > > > > It is enough? > > No. We need something like: > > if (blen < compressBound(size)) { > if (!f->ops->writev_buffer && !f->ops->put_buffer) { > return 0; > } > qemu_fflush(f); > blen = IO_BUF_SIZE - f->buf_index - sizeof(int32_t); > if (blen < compressBound(size)) { > return 0; > } > } > > > No? >
I got it. You mean we should not only consider the 'f' is not writable, but also the case where 'size' is a big value. You are right. I will change it. Thanks. Liang