summaryrefslogtreecommitdiff
path: root/ruby.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-05-10 02:54:04 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-05-10 02:54:04 +0000
commit23c74845eda6cab10ac3b5e1b98e75fc73bfde75 (patch)
tree7d51a18a8a4f781a50848ed54aefe46dee954c83 /ruby.c
parentb74131132f8872d23e405c61ecfe18dece17292f (diff)
RSTRING_PTR is not guaranteed to be char*-aligned
We need to ensure aligned memory access by allocating another memory region. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63388 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/ruby.c b/ruby.c
index 897728ce48..27f15d502d 100644
--- a/ruby.c
+++ b/ruby.c
@@ -759,6 +759,7 @@ moreswitches(const char *s, ruby_cmdline_options_t *opt, int envopt)
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_options_t *opt, int envopt)
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_options_t *opt, int envopt)
}
}
+ ruby_xfree(ptr);
/* get rid of GC */
rb_str_resize(argary, 0);
rb_str_resize(argstr, 0);