diff options
Diffstat (limited to 'src/lib/libc/stdlib/malloc.c')
| -rw-r--r-- | src/lib/libc/stdlib/malloc.c | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index b0083cb91e..40c602a1ae 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: malloc.c,v 1.239 2018/01/08 12:20:23 otto Exp $ */ | 1 | /* $OpenBSD: malloc.c,v 1.240 2018/01/18 08:37:28 otto Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net> | 3 | * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net> |
| 4 | * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> | 4 | * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> |
| @@ -931,7 +931,7 @@ malloc_bytes(struct dir_info *d, size_t size, void *f) | |||
| 931 | u_int i, r; | 931 | u_int i, r; |
| 932 | int j, listnum; | 932 | int j, listnum; |
| 933 | size_t k; | 933 | size_t k; |
| 934 | u_short u, b, *lp; | 934 | u_short *lp; |
| 935 | struct chunk_info *bp; | 935 | struct chunk_info *bp; |
| 936 | void *p; | 936 | void *p; |
| 937 | 937 | ||
| @@ -960,15 +960,12 @@ malloc_bytes(struct dir_info *d, size_t size, void *f) | |||
| 960 | /* start somewhere in a short */ | 960 | /* start somewhere in a short */ |
| 961 | lp = &bp->bits[i / MALLOC_BITS]; | 961 | lp = &bp->bits[i / MALLOC_BITS]; |
| 962 | if (*lp) { | 962 | if (*lp) { |
| 963 | b = *lp; | 963 | j = i % MALLOC_BITS; |
| 964 | k = i % MALLOC_BITS; | 964 | k = ffs(*lp >> j); |
| 965 | u = 1 << k; | 965 | if (k != 0) { |
| 966 | while (k < MALLOC_BITS) { | 966 | k += j - 1; |
| 967 | if (b & u) | 967 | goto found; |
| 968 | goto found; | 968 | } |
| 969 | k++; | ||
| 970 | u <<= 1; | ||
| 971 | } | ||
| 972 | } | 969 | } |
| 973 | /* no bit halfway, go to next full short */ | 970 | /* no bit halfway, go to next full short */ |
| 974 | i /= MALLOC_BITS; | 971 | i /= MALLOC_BITS; |
| @@ -977,15 +974,8 @@ malloc_bytes(struct dir_info *d, size_t size, void *f) | |||
| 977 | i = 0; | 974 | i = 0; |
| 978 | lp = &bp->bits[i]; | 975 | lp = &bp->bits[i]; |
| 979 | if (*lp) { | 976 | if (*lp) { |
| 980 | b = *lp; | 977 | k = ffs(*lp) - 1; |
| 981 | k = 0; | 978 | break; |
| 982 | u = 1; | ||
| 983 | for (;;) { | ||
| 984 | if (b & u) | ||
| 985 | goto found; | ||
| 986 | k++; | ||
| 987 | u <<= 1; | ||
| 988 | } | ||
| 989 | } | 979 | } |
| 990 | } | 980 | } |
| 991 | found: | 981 | found: |
| @@ -996,7 +986,7 @@ found: | |||
| 996 | } | 986 | } |
| 997 | #endif | 987 | #endif |
| 998 | 988 | ||
| 999 | *lp ^= u; | 989 | *lp ^= 1 << k; |
| 1000 | 990 | ||
| 1001 | /* If there are no more free, remove from free-list */ | 991 | /* If there are no more free, remove from free-list */ |
| 1002 | if (--bp->free == 0) | 992 | if (--bp->free == 0) |
