aboutsummaryrefslogtreecommitdiffstats
path: root/vmemalloc.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-06-11 16:37:09 +0200
committerMattias Andrée <maandree@kth.se>2022-06-11 16:37:09 +0200
commitfcfe59c1f2219408ac2a9cd84b386816ff252221 (patch)
tree0f46c009babfba2d0200ece3ecce067c548a66b6 /vmemalloc.c
parentRemove `static` from some `static inline` (diff)
downloadlibsimple-fcfe59c1f2219408ac2a9cd84b386816ff252221.tar.gz
libsimple-fcfe59c1f2219408ac2a9cd84b386816ff252221.tar.bz2
libsimple-fcfe59c1f2219408ac2a9cd84b386816ff252221.tar.xz
Fix warnings, replace some static inline with inline + extern inline, and fix glibc support
Diffstat (limited to 'vmemalloc.c')
-rw-r--r--vmemalloc.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/vmemalloc.c b/vmemalloc.c
index 8d92035..cbaecea 100644
--- a/vmemalloc.c
+++ b/vmemalloc.c
@@ -76,7 +76,7 @@ vmemalloc_parse_args(struct memalloc_state *state, size_t n, va_list ap)
case LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT:
if (state->zero_init >= 0)
goto inval;
- state->zero_init = va_arg(ap, int);
+ state->zero_init = (char)va_arg(ap, int);
state->zero_init = !!state->zero_init;
break;
@@ -158,7 +158,6 @@ vmemalloc_parse_args(struct memalloc_state *state, size_t n, va_list ap)
}
}
- return 0;
inval:
errno = EINVAL;
return -1;
@@ -170,11 +169,23 @@ gcd(size_t u, size_t v)
size_t t;
int shift = 0;
/* Not needed because u>0, v>0: if (!(u | v)) return u + v; */
- while (!((u | v) & 1)) u >>= 1, v >>= 1, shift++;
- while (!(u & 1)) u >>= 1;
+ while (!((u | v) & 1)) {
+ u >>= 1;
+ v >>= 1;
+ shift++;
+ }
+ while (!(u & 1)) {
+ u >>= 1;
+ }
do {
- while (!(v & 1)) v >>= 1;
- if (u > v) t = u, u = v, v = t;
+ while (!(v & 1)) {
+ v >>= 1;
+ }
+ if (u > v) {
+ t = u;
+ u = v;
+ v = t;
+ }
} while (v -= u);
return u << shift;
}