crypto/block-luks: make range overlap check more readable
authorYao Xingtao <yaoxt.fnst@fujitsu.com>
Mon, 22 Jul 2024 04:07:40 +0000 (00:07 -0400)
committerPhilippe Mathieu-Daudé <philmd@linaro.org>
Tue, 23 Jul 2024 18:30:36 +0000 (20:30 +0200)
use ranges_overlap() instead of open-coding the overlap check to improve
the readability of the code.

Signed-off-by: Yao Xingtao <yaoxt.fnst@fujitsu.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-ID: <20240722040742.11513-12-yaoxt.fnst@fujitsu.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
crypto/block-luks.c

index 5b777c15d3cd0b1007e2f95c73eb29774f782859..45347adeeb71027cf8977f83389fb860c7429b1a 100644 (file)
@@ -33,6 +33,7 @@
 #include "qemu/uuid.h"
 
 #include "qemu/bitmap.h"
+#include "qemu/range.h"
 
 /*
  * Reference for the LUKS format implemented here is
@@ -572,7 +573,7 @@ qcrypto_block_luks_check_header(const QCryptoBlockLUKS *luks,
                                                        header_sectors,
                                                        slot2->stripes);
 
-            if (start1 + len1 > start2 && start2 + len2 > start1) {
+            if (ranges_overlap(start1, len1, start2, len2)) {
                 error_setg(errp,
                            "Keyslots %zu and %zu are overlapping in the header",
                            i, j);