Fix alignment bug in assoc.c
Showing
1 changed file
with
14 additions
and
2 deletions
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 2007 Free Software Foundation, Inc. | 2 | Copyright (C) 2007, 2009 Free Software Foundation, Inc. |
3 | 3 | ||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | 4 | GNU Mailutils is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 5 | it under the terms of the GNU General Public License as published by |
... | @@ -58,7 +58,19 @@ struct _mu_assoc | ... | @@ -58,7 +58,19 @@ struct _mu_assoc |
58 | mu_iterator_t itr; | 58 | mu_iterator_t itr; |
59 | }; | 59 | }; |
60 | 60 | ||
61 | #define ASSOC_ELEM_SIZE(a) ((a)->elsize + sizeof(struct _mu_assoc_elem) - 1) | 61 | struct _mu_assoc_elem_align |
62 | { | ||
63 | char c; | ||
64 | struct _mu_assoc_elem x; | ||
65 | }; | ||
66 | |||
67 | #define __ASSOC_ELEM_ALIGNMENT (mu_offsetof(struct _mu_assoc_elem_align, x)) | ||
68 | |||
69 | #define __ASSOC_ELEM_SIZE(a) \ | ||
70 | ((a)->elsize + mu_offsetof(struct _mu_assoc_elem, data)) | ||
71 | #define __ASSOC_ALIGN(a, b) (((a) + (b) - 1) & ~((b) - 1)) | ||
72 | #define ASSOC_ELEM_SIZE(a) \ | ||
73 | __ASSOC_ALIGN(__ASSOC_ELEM_SIZE(a),__ASSOC_ELEM_ALIGNMENT) | ||
62 | 74 | ||
63 | #define __ASSOC_ELEM(a,p,n) \ | 75 | #define __ASSOC_ELEM(a,p,n) \ |
64 | ((struct _mu_assoc_elem*) ((char*) (p) + ASSOC_ELEM_SIZE (a) * n)) | 76 | ((struct _mu_assoc_elem*) ((char*) (p) + ASSOC_ELEM_SIZE (a) * n)) | ... | ... |
-
Please register or sign in to post a comment