ruby-changes:48513
From: yui-knk <ko1@a...>
Date: Fri, 3 Nov 2017 12:22:28 +0900 (JST)
Subject: [ruby-changes:48513] yui-knk:r60628 (trunk): node.c: Fix possible alignment bugs
yui-knk 2017-11-03 12:22:23 +0900 (Fri, 03 Nov 2017) New Revision: 60628 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60628 Log: 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. Modified files: trunk/node.c Index: node.c =================================================================== --- node.c (revision 60627) +++ node.c (revision 60628) @@ -1235,7 +1235,7 @@ struct node_buffer_struct { https://github.com/ruby/ruby/blob/trunk/node.c#L1235 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) https://github.com/ruby/ruby/blob/trunk/node.c#L1263 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; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/