From b013f9976e2d620094d3d4584ee8243df2b9c87f Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Sun, 31 Dec 2006 10:03:54 +0000 Subject: ensure that all arrays that are allocated in the buffer are now aligned to the pointer size git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@209 ef36b2f9-881f-0410-afb5-c4e39611909c --- nslcd-common.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'nslcd-common.h') diff --git a/nslcd-common.h b/nslcd-common.h index 6150075..a283fb4 100644 --- a/nslcd-common.h +++ b/nslcd-common.h @@ -168,8 +168,19 @@ static void debug_dump(const void *ptr,size_t size) BUF_CHECK(fp,tmp2int32); \ BUF_SKIP(tmp2int32); +/* move BUF_CUR foreward so that it is aligned to the specified + type width */ +#define BUF_ALIGN(fp,type) \ + /* figure out number of bytes to skip foreward */ \ + tmp2int32=(sizeof(type)-((BUF_CUR-(char *)NULL)%sizeof(type)))%sizeof(type); \ + /* check and skip */ \ + BUF_CHECK(fp,tmp2int32); \ + BUF_SKIP(tmp2int32); + /* allocate a piece of the buffer to store an array in */ #define BUF_ALLOC(fp,ptr,type,num) \ + /* align to the specified type width */ \ + BUF_ALIGN(fp,type); \ /* check that we have enough room */ \ BUF_CHECK(fp,(num)*sizeof(type)); \ /* store the pointer */ \ -- cgit v1.2.3