1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
diff --git a/lib/malloca.c b/lib/malloca.c
index e75c72df84..6938cdce7a 100644
--- a/lib/malloca.c
+++ b/lib/malloca.c
@@ -69,25 +69,27 @@ mmalloca (size_t n)
theoretical platforms where UINTPTR_MAX <= INT_MAX. */
uintptr_t umemplus;
ckd_add (&umemplus, umem, sizeof (small_t) + sa_alignment_max - 1);
- idx_t offset = (umemplus - umemplus % (2 * sa_alignment_max)
- + sa_alignment_max - umem);
- void *p = mem + offset;
- /* Here p >= mem + sizeof (small_t),
- and p <= mem + sizeof (small_t) + 2 * sa_alignment_max - 1
- hence p + n <= mem + nplus.
- So, the memory range [p, p+n) lies in the allocated memory range
- [mem, mem + nplus). */
- small_t *sp = p;
+ {
+ idx_t offset = (umemplus - umemplus % (2 * sa_alignment_max)
+ + sa_alignment_max - umem);
+ void *p = mem + offset;
+ /* Here p >= mem + sizeof (small_t),
+ and p <= mem + sizeof (small_t) + 2 * sa_alignment_max - 1
+ hence p + n <= mem + nplus.
+ So, the memory range [p, p+n) lies in the allocated memory range
+ [mem, mem + nplus). */
+ small_t *sp = p;
# if defined __CHERI_PURE_CAPABILITY__
- sp[-1] = umem;
- p = (char *) cheri_bounds_set ((char *) p - sizeof (small_t),
- sizeof (small_t) + n)
+ sp[-1] = umem;
+ p = (char *) cheri_bounds_set ((char *) p - sizeof (small_t),
+ sizeof (small_t) + n)
+ sizeof (small_t);
# else
- sp[-1] = offset;
+ sp[-1] = offset;
# endif
- /* p ≡ sa_alignment_max mod 2*sa_alignment_max. */
- return p;
+ /* p ≡ sa_alignment_max mod 2*sa_alignment_max. */
+ return p;
+ }
}
}
/* Out of memory. */
|