зеркало из https://github.com/github/ruby.git
RSTRING_PTR is not guaranteed to be char*-aligned
This commit eliminates (char **)RSTRING_PTR(...) like usages. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63414 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
8b88f70a84
Коммит
4f3c4c7d6d
31
internal.h
31
internal.h
|
@ -964,6 +964,24 @@ VALUE rb_imemo_tmpbuf_auto_free_pointer(void *buf);
|
|||
VALUE rb_imemo_tmpbuf_auto_free_maybe_mark_buffer(void *buf, size_t cnt);
|
||||
rb_imemo_tmpbuf_t *rb_imemo_tmpbuf_parser_heap(void *buf, rb_imemo_tmpbuf_t *old_heap, size_t cnt);
|
||||
|
||||
#define RB_IMEMO_TMPBUF_PTR(v) \
|
||||
((void *)(((const struct rb_imemo_tmpbuf_struct *)(v))->ptr))
|
||||
|
||||
static inline VALUE
|
||||
rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(VALUE str)
|
||||
{
|
||||
const void *src;
|
||||
void *dst;
|
||||
size_t len;
|
||||
|
||||
SafeStringValue(str);
|
||||
len = RSTRING_LEN(str);
|
||||
src = RSTRING_PTR(str);
|
||||
dst = ruby_xmalloc(len);
|
||||
memcpy(dst, src, len);
|
||||
return rb_imemo_tmpbuf_auto_free_pointer(dst);
|
||||
}
|
||||
|
||||
void rb_strterm_mark(VALUE obj);
|
||||
|
||||
/*! MEMO
|
||||
|
@ -1679,8 +1697,17 @@ struct rb_execarg {
|
|||
* The beginning one is for /bin/sh used by exec_with_sh.
|
||||
* The last one for terminating NULL used by execve.
|
||||
* See rb_exec_fillarg() in process.c. */
|
||||
#define ARGVSTR2ARGC(argv_str) (RSTRING_LEN(argv_str) / sizeof(char *) - 2)
|
||||
#define ARGVSTR2ARGV(argv_str) ((char **)RSTRING_PTR(argv_str) + 1)
|
||||
#define ARGVSTR2ARGV(argv_str) ((char **)RB_IMEMO_TMPBUF_PTR(argv_str) + 1)
|
||||
|
||||
static inline size_t
|
||||
ARGVSTR2ARGC(VALUE argv_str)
|
||||
{
|
||||
size_t i = 0;
|
||||
char *const *p = ARGVSTR2ARGV(argv_str);
|
||||
while (p[i++])
|
||||
;
|
||||
return i - 1;
|
||||
}
|
||||
|
||||
rb_pid_t rb_fork_ruby(int *status);
|
||||
void rb_last_status_clear(void);
|
||||
|
|
10
process.c
10
process.c
|
@ -1283,7 +1283,7 @@ proc_exec_cmd(const char *prog, VALUE argv_str, VALUE envp_str)
|
|||
rb_w32_uaspawn(P_OVERLAY, prog, argv);
|
||||
return errno;
|
||||
#else
|
||||
envp = envp_str ? (char **)RSTRING_PTR(envp_str) : NULL;
|
||||
envp = envp_str ? RB_IMEMO_TMPBUF_PTR(envp_str) : NULL;
|
||||
if (envp_str)
|
||||
execve(prog, argv, envp); /* async-signal-safe */
|
||||
else
|
||||
|
@ -1324,7 +1324,7 @@ proc_exec_sh(const char *str, VALUE envp_str)
|
|||
}
|
||||
#else
|
||||
if (envp_str)
|
||||
execle("/bin/sh", "sh", "-c", str, (char *)NULL, (char **)RSTRING_PTR(envp_str)); /* async-signal-safe */
|
||||
execle("/bin/sh", "sh", "-c", str, (char *)NULL, RB_IMEMO_TMPBUF_PTR(envp_str)); /* async-signal-safe */
|
||||
else
|
||||
execl("/bin/sh", "sh", "-c", str, (char *)NULL); /* async-signal-safe (since SUSv4) */
|
||||
#endif /* _WIN32 */
|
||||
|
@ -2264,7 +2264,8 @@ rb_exec_fillarg(VALUE prog, int argc, VALUE *argv, VALUE env, VALUE opthash, VAL
|
|||
p += strlen(p) + 1;
|
||||
}
|
||||
rb_str_buf_cat(argv_str, (char *)&null, sizeof(null)); /* terminator for execve. */
|
||||
eargp->invoke.cmd.argv_str = argv_str;
|
||||
eargp->invoke.cmd.argv_str =
|
||||
rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(argv_str);
|
||||
}
|
||||
RB_GC_GUARD(execarg_obj);
|
||||
}
|
||||
|
@ -2464,7 +2465,8 @@ rb_execarg_parent_start1(VALUE execarg_obj)
|
|||
}
|
||||
p = NULL;
|
||||
rb_str_buf_cat(envp_str, (char *)&p, sizeof(p));
|
||||
eargp->envp_str = envp_str;
|
||||
eargp->envp_str =
|
||||
rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(envp_str);
|
||||
eargp->envp_buf = envp_buf;
|
||||
|
||||
/*
|
||||
|
|
Загрузка…
Ссылка в новой задаче