diff options
author | Ken Brown <kbrown@cornell.edu> | 2014-03-04 14:02:49 -0500 |
---|---|---|
committer | Ken Brown <kbrown@cornell.edu> | 2014-03-04 14:02:49 -0500 |
commit | 94a089b5f873837a369a176c114430e0fd0bee05 (patch) | |
tree | fc365dfb7932c2c250537844f567540f7173c7f2 /src/gmalloc.c | |
parent | 201572eca80ea77d8e1c25099b4aa2d98bc4d402 (diff) | |
download | emacs-94a089b5f873837a369a176c114430e0fd0bee05.tar.gz |
Further follow-up to last change in gmalloc.c.
* src/gmalloc.c (aligned_alloc): Clarify the code by making `adj'
represent the actual adjustment needed for alignment.
Diffstat (limited to 'src/gmalloc.c')
-rw-r--r-- | src/gmalloc.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/gmalloc.c b/src/gmalloc.c index 9fd62407285..977abbdbbbd 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c @@ -1597,34 +1597,34 @@ aligned_alloc (size_t alignment, size_t size) /* Figure out how much we will need to pad this particular block to achieve the required alignment. */ - adj = (uintptr_t) result % alignment; - if (adj == 0) - adj = alignment; + adj = alignment - (uintptr_t) result % alignment; + if (adj == alignment) + adj = 0; - if (adj != 1) + if (adj != alignment - 1) { do { /* Reallocate the block with only as much excess as it needs. */ free (result); - result = malloc (size + alignment - adj); + result = malloc (size + adj); if (result == NULL) /* Impossible unless interrupted. */ return NULL; lastadj = adj; - adj = (uintptr_t) result % alignment; - if (adj == 0) - adj = alignment; + adj = alignment - (uintptr_t) result % alignment; + if (adj == alignment) + adj = 0; /* It's conceivable we might have been so unlucky as to get a different block with weaker alignment. If so, this block is too short to contain SIZE after alignment correction. So we must try again and get another block, slightly larger. */ - } while (adj < lastadj); + } while (adj > lastadj); } - if (adj != alignment) + if (adj != 0) { /* Record this block in the list of aligned blocks, so that `free' can identify the pointer it is passed, which will be in the middle @@ -1648,7 +1648,7 @@ aligned_alloc (size_t alignment, size_t size) if (l != NULL) { l->exact = result; - result = l->aligned = (char *) result + alignment - adj; + result = l->aligned = (char *) result + adj; } UNLOCK_ALIGNED_BLOCKS (); if (l == NULL) |