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

ruby-changes:51181

From: shyouhei <ko1@a...>
Date: Thu, 10 May 2018 11:54:09 +0900 (JST)
Subject: [ruby-changes:51181] shyouhei:r63388 (trunk): RSTRING_PTR is not guaranteed to be char*-aligned

shyouhei	2018-05-10 11:54:04 +0900 (Thu, 10 May 2018)

  New Revision: 63388

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

  Log:
    RSTRING_PTR is not guaranteed to be char*-aligned
    
    We need to ensure aligned memory access by allocating
    another memory region.

  Modified files:
    trunk/ruby.c
Index: ruby.c
===================================================================
--- ruby.c	(revision 63387)
+++ ruby.c	(revision 63388)
@@ -759,6 +759,7 @@ moreswitches(const char *s, ruby_cmdline https://github.com/ruby/ruby/blob/trunk/ruby.c#L759
     char **argv, *p;
     const char *ap = 0;
     VALUE argstr, argary;
+    void *ptr;
 
     while (ISSPACE(*s)) s++;
     if (!*s) return;
@@ -781,7 +782,8 @@ moreswitches(const char *s, ruby_cmdline https://github.com/ruby/ruby/blob/trunk/ruby.c#L782
     argc = RSTRING_LEN(argary) / sizeof(ap);
     ap = 0;
     rb_str_cat(argary, (char *)&ap, sizeof(ap));
-    argv = (char **)RSTRING_PTR(argary);
+    argv = ptr = ALLOC_N(char *, argc);
+    MEMMOVE(argv, RSTRING_PTR(argary), char *, argc);
 
     while ((i = proc_options(argc, argv, opt, envopt)) > 1 && envopt && (argc -= i) > 0) {
 	argv += i;
@@ -794,6 +796,7 @@ moreswitches(const char *s, ruby_cmdline https://github.com/ruby/ruby/blob/trunk/ruby.c#L796
 	}
     }
 
+    ruby_xfree(ptr);
     /* get rid of GC */
     rb_str_resize(argary, 0);
     rb_str_resize(argstr, 0);

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

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