* grub-core/net/netbuff.c (grub_netbuff_alloc): Ensure proper alignment.

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-12-13 02:15:09 +01:00
parent 564840dc3d
commit f138623a60
2 changed files with 8 additions and 1 deletions

View file

@ -1,3 +1,7 @@
2011-12-13 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/net/netbuff.c (grub_netbuff_alloc): Ensure proper alignment.
2011-12-13 Vladimir Serbinenko <phcoder@gmail.com> 2011-12-13 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/disk/mdraid_linux.c (grub_mdraid_detect): Change pointer * grub-core/disk/mdraid_linux.c (grub_mdraid_detect): Change pointer

View file

@ -78,6 +78,8 @@ grub_netbuff_alloc (grub_size_t len)
struct grub_net_buff *nb; struct grub_net_buff *nb;
void *data; void *data;
COMPILE_TIME_ASSERT (NETBUFF_ALIGN % sizeof (grub_properly_aligned_t) == 0);
if (len < NETBUFFMINLEN) if (len < NETBUFFMINLEN)
len = NETBUFFMINLEN; len = NETBUFFMINLEN;
@ -85,7 +87,8 @@ grub_netbuff_alloc (grub_size_t len)
data = grub_memalign (NETBUFF_ALIGN, len + sizeof (*nb)); data = grub_memalign (NETBUFF_ALIGN, len + sizeof (*nb));
if (!data) if (!data)
return NULL; return NULL;
nb = (struct grub_net_buff *) ((grub_uint8_t *) data + len); nb = (struct grub_net_buff *) ((grub_properly_aligned_t *) data
+ len / sizeof (grub_properly_aligned_t));
nb->head = nb->data = nb->tail = data; nb->head = nb->data = nb->tail = data;
nb->end = (char *) nb; nb->end = (char *) nb;
return nb; return nb;