Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Hess <thess@kitschensync.net>2017-02-23 23:57:02 +0300
committerTed Hess <thess@kitschensync.net>2017-02-24 23:00:15 +0300
commit96305a3cafcc9c0df7f189567671bb26ce3eb129 (patch)
treeaf560b7fb90246bc69703a626b25f2db77f44b55 /utils.c
parentde3f14b643f09c799845073eaf3577a334d0726d (diff)
libubox: Change calloc_a() to return size_t aligned pointers
Un-aligned pointers were causing seg faults on some targets Signed-off-by: Ted Hess <thess@kitschensync.net>
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/utils.c b/utils.c
index 5d9d5aa..765dd8b 100644
--- a/utils.c
+++ b/utils.c
@@ -27,6 +27,9 @@
_addr; \
_addr = va_arg(_arg, void **), _len = _addr ? va_arg(_arg, size_t) : 0)
+#define C_PTR_ALIGN (sizeof(size_t))
+#define C_PTR_MASK (-C_PTR_ALIGN)
+
void *__calloc_a(size_t len, ...)
{
va_list ap, ap1;
@@ -40,7 +43,7 @@ void *__calloc_a(size_t len, ...)
va_copy(ap1, ap);
foreach_arg(ap1, cur_addr, cur_len, &ret, len)
- alloc_len += cur_len;
+ alloc_len += (cur_len + C_PTR_ALIGN - 1 ) & C_PTR_MASK;
va_end(ap1);
ptr = calloc(1, alloc_len);
@@ -49,7 +52,7 @@ void *__calloc_a(size_t len, ...)
alloc_len = 0;
foreach_arg(ap, cur_addr, cur_len, &ret, len) {
*cur_addr = &ptr[alloc_len];
- alloc_len += cur_len;
+ alloc_len += (cur_len + C_PTR_ALIGN - 1) & C_PTR_MASK;
}
va_end(ap);