diff --git a/src/readthrd.c b/src/readthrd.c index 13d64e1..d167701 100644 --- a/src/readthrd.c +++ b/src/readthrd.c @@ -180,10 +180,17 @@ static ssize_t check_file(const char *f) return ret; } - static int next_power_of_2(int x) { - return (x & -x) + x; + x--; + x |= x >> 1; + x |= x >> 2; + x |= x >> 4; + x |= x >> 8; + x |= x >> 16; + x++; + + return x; } struct readthrd *readthrd_start(const char *fpath, diff --git a/src/writethrd.c b/src/writethrd.c index 2f5c147..ab7b6c2 100644 --- a/src/writethrd.c +++ b/src/writethrd.c @@ -200,7 +200,15 @@ static int check_file(const char *f, int truncate) static int next_power_of_2(int x) { - return (x & -x) + x; + x--; + x |= x >> 1; + x |= x >> 2; + x |= x >> 4; + x |= x >> 8; + x |= x >> 16; + x++; + + return x; } struct writethrd *writethrd_start(const char *fpath, const char *swap_phrase,