summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGao Xiang <hsiangkao@aol.com>2019-10-14 19:11:30 +0800
committerGao Xiang <hsiangkao@aol.com>2019-10-15 23:56:03 +0800
commit0e91d131dcb21b45b21762c77c6d0377fa16f80d (patch)
treef6b0f34f4d844324fe39652a8e0dc10ee2ad2d71
parent561cf9fb45d712e0dd460a03b8cb2b27f658f50b (diff)
erofs-utils: use cmpsgn(x, y) for standardized large value comparsion
Previously, roundup(bb->buffers.off % EROFS_BLKSIZ, alignsize) + incr + extrasize is an unsigned 64bit value and sgn(x) didn't work properly. Fix it. Link: https://lore.kernel.org/r/20191015155025.13215-1-hsiangkao@aol.com Fixes: b0ca535297b6 ("erofs-utils: support 64-bit internal buffer cache") Reviewed-and-tested-by: Li Guifu <blucerlee@gmail.com> Signed-off-by: Gao Xiang <hsiangkao@aol.com>
-rw-r--r--include/erofs/defs.h5
-rw-r--r--lib/cache.c6
2 files changed, 6 insertions, 5 deletions
diff --git a/include/erofs/defs.h b/include/erofs/defs.h
index 15db4e3..d3c1156 100644
--- a/include/erofs/defs.h
+++ b/include/erofs/defs.h
@@ -136,9 +136,10 @@ typedef int64_t s64;
type __max2 = (y); \
__max1 > __max2 ? __max1: __max2; })
-#define sgn(x) ({ \
+#define cmpsgn(x, y) ({ \
typeof(x) _x = (x); \
-(_x > 0) - (_x < 0); })
+ typeof(y) _y = (y); \
+ (_x > _y) - (_x < _y); })
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
diff --git a/lib/cache.c b/lib/cache.c
index 41d2d5d..e61b201 100644
--- a/lib/cache.c
+++ b/lib/cache.c
@@ -80,9 +80,9 @@ static int __erofs_battach(struct erofs_buffer_block *bb,
bool dryrun)
{
const erofs_off_t alignedoffset = roundup(bb->buffers.off, alignsize);
- const int oob = sgn(roundup(bb->buffers.off % EROFS_BLKSIZ,
- alignsize) + incr + extrasize -
- EROFS_BLKSIZ);
+ const int oob = cmpsgn(roundup(bb->buffers.off % EROFS_BLKSIZ,
+ alignsize) + incr + extrasize,
+ EROFS_BLKSIZ);
bool tailupdate = false;
erofs_blk_t blkaddr;