use range_overlaps_range() instead of open-coding the overlap check to improve the readability of the code.
Signed-off-by: Yao Xingtao <yaoxt.f...@fujitsu.com> --- block/vhdx.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/block/vhdx.c b/block/vhdx.c index 5aa1a1350626..c31661b946b6 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -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; } -- 2.41.0