Am 06.09.2019 um 21:17 hat Eric Blake geschrieben: > > - assert((offset_in_cluster & ~BDRV_SECTOR_MASK) == 0); > > + assert((guest_offset & ~BDRV_SECTOR_MASK) == 0); > > + assert((host_offset & ~BDRV_SECTOR_MASK) == 0); > > assert((bytes & ~BDRV_SECTOR_MASK) == 0); > > Pre-existing, but we could use QEMU_IS_ALIGNED(x, BDRV_SECTOR_SIZE) for > slightly more legibility than open-coding the bit operation. > > Neat trick about power-of-2 alignment checks: > > assert(QEMU_IS_ALIGNED(offset_in_cluster | guest_offset | > host_offset | bytes, BDRV_SECTOR_SIZE)); > > gives the same result in one assertion. (I've used it elsewhere in the > code base, but I'm not opposed to one assert per variable if you think > batching is too dense.)
A possible downside of this is that if a user reports an assertion failure, you can't tell any more which of the variables ended up in a bad state. If you're lucky, you can still tell in gdb at least if the bug is reproducible, but I wouldn't be surprised if in release builds, half of the variables were actually optimised away, so that even this wouldn't work. Kevin
signature.asc
Description: PGP signature