From 04dfc46ad0918964260d095b8f58e35eff5a33af Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 5 Apr 2018 07:00:08 +0000 Subject: compile.c: zero fill * compile.c (ibf_dump_align): fill padding with zero, instead of resizing only, not to leave garbages. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- compile.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'compile.c') diff --git a/compile.c b/compile.c index 957737236d..33bc02625c 100644 --- a/compile.c +++ b/compile.c @@ -8231,13 +8231,17 @@ ibf_dump_align(struct ibf_dump *dump, size_t align) { ibf_offset_t pos = ibf_dump_pos(dump); if (pos % align) { - long size = (long)pos - (pos % align) + align; + static const char padding[sizeof(VALUE)]; + size_t size = align - ((size_t)pos % align); #if SIZEOF_LONG > SIZEOF_INT - if (pos >= UINT_MAX) { + if (pos + size >= UINT_MAX) { rb_raise(rb_eRuntimeError, "dump size exceeds"); } #endif - rb_str_resize(dump->str, size); + for (; size > sizeof(padding); size -= sizeof(padding)) { + rb_str_cat(dump->str, padding, sizeof(padding)); + } + rb_str_cat(dump->str, padding, size); } } -- cgit v1.2.3