- /* Reallocate the block with only as much excess as it needs. */
- free (result);
- result = malloc (adj + size);
- if (result == NULL) /* Impossible unless interrupted. */
- return NULL;
-
- lastadj = adj;
- adj = (uintptr_t) result % alignment;
- /* 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);
+ do
+ {
+ /* Reallocate the block with only as much excess as it
+ needs. */
+ free (result);
+ result = malloc (size + adj);
+ if (result == NULL) /* Impossible unless interrupted. */
+ return NULL;
+
+ lastadj = adj;
+ 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);
+ }