]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/blkdev: use off_t for max values
authorSamanta Navarro <ferivoz@riseup.net>
Fri, 13 Jan 2023 11:52:36 +0000 (11:52 +0000)
committerSamanta Navarro <ferivoz@riseup.net>
Mon, 16 Jan 2023 12:05:26 +0000 (12:05 +0000)
The off_t datatype is signed. Use it for high and low boundaries as
well to support also very large block devices close to its limits.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
lib/blkdev.c

index 757f3e818b0283af9a493971d804b256709463de..b10da99a246b06614cab9e247c4a6d38f635c9ef 100644 (file)
@@ -58,25 +58,25 @@ int is_blkdev(int fd)
 
 off_t
 blkdev_find_size (int fd) {
-       uintmax_t high, low = 0;
+       off_t high, low = 0;
 
        for (high = 1024; blkdev_valid_offset (fd, high); ) {
-               if (high == UINTMAX_MAX) {
+               if (high == SINT_MAX(off_t)) {
                        errno = EFBIG;
                        return -1;
                }
 
                low = high;
 
-               if (high >= UINTMAX_MAX/2)
-                       high = UINTMAX_MAX;
+               if (high >= SINT_MAX(off_t)/2)
+                       high = SINT_MAX(off_t);
                else
                        high *= 2;
        }
 
        while (low < high - 1)
        {
-               uintmax_t mid = (low + high) / 2;
+               off_t mid = (low + high) / 2;
 
                if (blkdev_valid_offset (fd, mid))
                        low = mid;