@@ -32,6 +32,7 @@
#include "qapi/qmp/qdict.h"
#include "qapi/qobject-input-visitor.h"
#include "qapi/qapi-visit-block-core.h"
+#include "qemu/range.h"
/* Options for VHDX creation */
@@ -231,15 +232,16 @@ void vhdx_guid_generate(MSGUID *guid)
static int vhdx_region_check(BDRVVHDXState *s, uint64_t start, uint64_t length)
{
int ret = 0;
- uint64_t end;
VHDXRegionEntry *r;
+ Range range1, range2;
- end = start + length;
+ range_init_nofail(&range1, start, length);
QLIST_FOREACH(r, &s->regions, entries) {
- if (!((start >= r->end) || (end <= r->start))) {
+ range_init_nofail(&range2, r->start, r->end - r->start);
+ if (range_overlaps_range(&range1, &range2)) {
error_report("VHDX region %" PRIu64 "-%" PRIu64 " overlaps with "
- "region %" PRIu64 "-%." PRIu64, start, end, r->start,
- r->end);
+ "region %" PRIu64 "-%." PRIu64, start, start + length,
+ r->start, r->end);
ret = -EINVAL;
goto exit;
}
use range_overlaps_range() instead of open-coding the overlap check to improve the readability of the code. Signed-off-by: Yao Xingtao <yaoxt.fnst@fujitsu.com> --- block/vhdx.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)