diff options
author | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-09 14:41:53 +0200 |
---|---|---|
committer | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-09 14:41:53 +0200 |
commit | 5fadc0cbb8577c61d66bd6f19ceaf0507c11e23b (patch) | |
tree | 684758441f5b431d0008253243034b6a4a29417c /src/alloc.c | |
parent | 249866e3d1e11dc72eaa1305f4bb479ded92ef38 (diff) |
initial clang-format
Diffstat (limited to 'src/alloc.c')
-rw-r--r-- | src/alloc.c | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/src/alloc.c b/src/alloc.c index 8ec0a7e..cee09ac 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -1,21 +1,27 @@ -#include <stdlib.h> +#include "alloc.h" + #include <errno.h> #include <limits.h> +#include <stdlib.h> + #include "byte.h" -#include "alloc.h" -#define ALIGNMENT 16 /* XXX: assuming that this alignment is enough */ -#define SPACE 4096 /* must be multiple of ALIGNMENT */ +#define ALIGNMENT 16 /* XXX: assuming that this alignment is enough */ +#define SPACE 4096 /* must be multiple of ALIGNMENT */ -typedef union { char irrelevant[ALIGNMENT]; double d; } aligned; +typedef union { + char irrelevant[ALIGNMENT]; + double d; +} aligned; static aligned realspace[SPACE / ALIGNMENT]; -#define space ((char *) realspace) +#define space ((char *)realspace) static unsigned int avail = SPACE; /* multiple of ALIGNMENT; 0<=avail<=SPACE */ -/*@null@*//*@out@*/char *alloc(unsigned int n) { +/*@null@*/ /*@out@*/ char *alloc(unsigned int n) +{ char *x; -/* Guninski exploit + patch from Qualys (CVE-2005-1513) */ + /* Guninski exploit + patch from Qualys (CVE-2005-1513) */ if (n >= (INT_MAX >> 3)) { errno = ENOMEM; @@ -23,27 +29,29 @@ static unsigned int avail = SPACE; /* multiple of ALIGNMENT; 0<=avail<=SPACE */ } n = ALIGNMENT + n - (n & (ALIGNMENT - 1)); /* XXX: could overflow */ - if (n <= avail) { avail -= n; return space + avail; } + if (n <= avail) { + avail -= n; + return space + avail; + } x = malloc(n); if (!x) errno = ENOMEM; return x; } -void alloc_free(char *x) +void alloc_free(char *x) { if (x >= space) - if (x < space + SPACE) - return; /* XXX: assuming that pointers are flat */ + if (x < space + SPACE) return; /* XXX: assuming that pointers are flat */ free(x); } -int alloc_re(char **x,unsigned int m,unsigned int n) +int alloc_re(char **x, unsigned int m, unsigned int n) { char *y; y = alloc(n); if (!y) return 0; - byte_copy(y,m,*x); + byte_copy(y, m, *x); qfree(*x); *x = y; return 1; |