summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-05 07:00:08 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-05 07:00:08 +0000
commit04dfc46ad0918964260d095b8f58e35eff5a33af (patch)
tree1ac3f29bf25ca0fa225f813e1e30530495cb34a9
parent4a7bf2efe702b64183259828de470d14df0f0031 (diff)
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
-rw-r--r--compile.c10
1 files changed, 7 insertions, 3 deletions
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);
}
}