summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compile.c2
-rw-r--r--file.c2
-rw-r--r--iseq.c4
-rw-r--r--iseq.h7
-rw-r--r--string.c2
-rw-r--r--variable.c2
6 files changed, 10 insertions, 9 deletions
diff --git a/compile.c b/compile.c
index 879d332e89..f4ae64bacc 100644
--- a/compile.c
+++ b/compile.c
@@ -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;
diff --git a/file.c b/file.c
index 5947b3f68b..7fdca684cc 100644
--- a/file.c
+++ b/file.c
@@ -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;
diff --git a/iseq.c b/iseq.c
index 57ff506d0a..20ad68e65e 100644
--- a/iseq.c
+++ b/iseq.c
@@ -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;
diff --git a/iseq.h b/iseq.h
index daeac0c889..283f5dcdf4 100644
--- a/iseq.h
+++ b/iseq.h
@@ -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)
diff --git a/string.c b/string.c
index 22734e0e1b..63b4d57f82 100644
--- a/string.c
+++ b/string.c
@@ -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 *