[前][次][番号順一覧][スレッド一覧]

ruby-changes:50891

From: nobu <ko1@a...>
Date: Thu, 5 Apr 2018 16:00:14 +0900 (JST)
Subject: [ruby-changes:50891] nobu:r63098 (trunk): compile.c: zero fill

nobu	2018-04-05 16:00:08 +0900 (Thu, 05 Apr 2018)

  New Revision: 63098

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63098

  Log:
    compile.c: zero fill
    
    * compile.c (ibf_dump_align): fill padding with zero, instead of
      resizing only, not to leave garbages.

  Modified files:
    trunk/compile.c
Index: compile.c
===================================================================
--- compile.c	(revision 63097)
+++ compile.c	(revision 63098)
@@ -8231,13 +8231,17 @@ ibf_dump_align(struct ibf_dump *dump, si https://github.com/ruby/ruby/blob/trunk/compile.c#L8231
 {
     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);
     }
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]