diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-14 11:19:18 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-14 11:19:18 +0000 |
commit | 6b5e0bd98c3a807ab7708e775ac9b60a4f59e427 (patch) | |
tree | 5e86e7f6ac8258b53aaef567a416e7caac4fdd66 | |
parent | bbea0270272720d6b97fa74cf59d20eee9519aa8 (diff) |
exclude flexible array size with old compilers
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61814 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | compile.c | 2 | ||||
-rw-r--r-- | file.c | 2 | ||||
-rw-r--r-- | iseq.c | 4 | ||||
-rw-r--r-- | iseq.h | 7 | ||||
-rw-r--r-- | string.c | 2 | ||||
-rw-r--r-- | variable.c | 2 |
6 files changed, 10 insertions, 9 deletions
@@ -868,7 +868,7 @@ compile_data_alloc(rb_iseq_t *iseq, size_t size) alloc_size *= 2; } storage->next = (void *)ALLOC_N(char, alloc_size + - sizeof(struct iseq_compile_data_storage)); + offsetof(struct iseq_compile_data_storage, buff)); storage = ISEQ_COMPILE_DATA(iseq)->storage_current = storage->next; storage->next = 0; storage->pos = 0; @@ -388,7 +388,7 @@ apply2files(int (*func)(const char *, void *), int argc, VALUE *argv, void *arg) { VALUE v; const size_t size = sizeof(struct apply_filename); - const long len = (long)(sizeof(struct apply_arg) + (size * argc)); + const long len = (long)(offsetof(struct apply_arg, fn) + (size * argc)); struct apply_arg *aa = ALLOCV(v, len); aa->errnum = 0; @@ -208,7 +208,7 @@ iseq_memsize(const rb_iseq_t *iseq) cur = compile_data->storage_head; while (cur) { - size += cur->size + sizeof(struct iseq_compile_data_storage); + size += cur->size + offsetof(struct iseq_compile_data_storage, buff); cur = cur->next; } } @@ -333,7 +333,7 @@ prepare_iseq_build(rb_iseq_t *iseq, ISEQ_COMPILE_DATA(iseq)->storage_head = ISEQ_COMPILE_DATA(iseq)->storage_current = (struct iseq_compile_data_storage *) ALLOC_N(char, INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE + - sizeof(struct iseq_compile_data_storage)); + offsetof(struct iseq_compile_data_storage, buff)); RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->catch_table_ary, rb_ary_tmp_new(3)); ISEQ_COMPILE_DATA(iseq)->storage_head->pos = 0; @@ -256,11 +256,12 @@ static inline int iseq_catch_table_bytes(int n) { enum { - catch_table_entries_max = (INT_MAX - sizeof(struct iseq_catch_table)) / sizeof(struct iseq_catch_table_entry) + catch_table_entry_size = sizeof(struct iseq_catch_table_entry), + catch_table_entries_max = (INT_MAX - offsetof(struct iseq_catch_table, entries)) / catch_table_entry_size }; if (n > catch_table_entries_max) rb_fatal("too large iseq_catch_table - %d", n); - return (int)(sizeof(struct iseq_catch_table) + - n * sizeof(struct iseq_catch_table_entry)); + return (int)(offsetof(struct iseq_catch_table, entries) + + n * catch_table_entry_size); } #define INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE (512) @@ -6410,7 +6410,7 @@ rb_str_casemap(VALUE source, OnigCaseFoldType *flags, rb_encoding *enc) if (CASEMAP_DEBUG) { fprintf(stderr, "Buffer allocation, capa is %"PRIuSIZE"\n", capa); /* for tuning */ } - current_buffer->next = xmalloc(sizeof(mapping_buffer) + capa); + current_buffer->next = xmalloc(offsetof(mapping_buffer, space) + capa); current_buffer = current_buffer->next; current_buffer->next = NULL; current_buffer->capa = capa; diff --git a/variable.c b/variable.c index 836686316f..1923f28f52 100644 --- a/variable.c +++ b/variable.c @@ -1001,7 +1001,7 @@ generic_ivar_get(VALUE obj, ID id, VALUE undef) static size_t gen_ivtbl_bytes(size_t n) { - return sizeof(struct gen_ivtbl) + n * sizeof(VALUE); + return offsetof(struct gen_ivtbl, ivptr) + n * sizeof(VALUE); } static struct gen_ivtbl * |