ref: 4ea133ddac02791432ad26864fbdad4f1d49120f
parent: 6abd8d7e95c9df2553a69d6f88c82a9c935f6b4e
author: Ori Bernstein <[email protected]>
date: Wed Dec 11 18:39:03 EST 2013
Zero alignments should just return the value. If alignment is zero, just return the size. This fixes a bug where we were aligning a zero-size item's stack offset, which led to the stack being reset to zero, causing values to alias.
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -479,7 +479,7 @@
size_t max(size_t a, size_t b);
size_t min(size_t a, size_t b);
-size_t align(size_t sz, size_t align);
+size_t align(size_t sz, size_t a);
/* suffix replacement */
char *swapsuffix(char *buf, size_t sz, char *s, char *suf, char *swap);
--- a/parse/util.c
+++ b/parse/util.c
@@ -375,8 +375,11 @@
return b;
}
-size_t align(size_t sz, size_t align)
+size_t align(size_t sz, size_t a)
{
- return (sz + align - 1) & ~(align - 1);
+ /* align to 0 just returns sz */
+ if (a == 0)
+ return sz;
+ return (sz + a - 1) & ~(a - 1);
}