diff options
author | yui-knk <yui-knk@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-11-03 03:22:23 +0000 |
---|---|---|
committer | yui-knk <yui-knk@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-11-03 03:22:23 +0000 |
commit | f7fb0867897ced531a33a014fb92998b0ed97ac0 (patch) | |
tree | bdf486e4987b309294ea3c31a5fd121c076f4cdf /node.c | |
parent | 77fae4b4c0f0db9c8c0a321bbcfda436c7303731 (diff) | |
download | ruby-f7fb0867897ced531a33a014fb92998b0ed97ac0.tar.gz |
node.c: Fix possible alignment bugs
* node.c (rb_node_buffer_new): Use offsetof for
node_buffer_t size calculation.
* node.c (rb_ast_newnode): Use offsetof for
node_buffer_elem_t size calculation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60628 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'node.c')
-rw-r--r-- | node.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -1235,7 +1235,7 @@ struct node_buffer_struct { node_buffer_t * rb_node_buffer_new() { - node_buffer_t *nb = xmalloc(sizeof(node_buffer_t) + 16 * sizeof(NODE)); + node_buffer_t *nb = xmalloc(offsetof(node_buffer_t, body) + offsetof(node_buffer_elem_t, buf) + 16 * sizeof(NODE)); nb->idx = 0; nb->len = 16; nb->head = &nb->body; @@ -1263,7 +1263,7 @@ rb_ast_newnode(rb_ast_t *ast) if (nb->idx >= nb->len) { long n = nb->len * 2; node_buffer_elem_t *nbe; - nbe = xmalloc(sizeof(node_buffer_elem_t) + n * sizeof(NODE)); + nbe = xmalloc(offsetof(node_buffer_elem_t, buf) + n * sizeof(NODE)); nb->idx = 0; nb->len = n; nbe->next = nb->head; |