1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

glibc says memcpy cannot take NULL

At least since 2004, glibc's <string.h> annotates memcpy as
__attribute__((__nonnull__)).  On the other hand the argv here,
which is passed from rb_funcallv, may be NULL.  Practically this
should never be a serious problem but for maximum safety, let's
avoid passing NULL here.
This commit is contained in:
Urabe, Shyouhei 2019-04-26 18:01:24 +09:00
parent a116f04cca
commit e7b18ca6d9

View file

@ -383,6 +383,13 @@ check_funcall_missing(rb_execution_context_t *ec, VALUE klass, VALUE recv, ID mi
VALUE argbuf, *new_args = ALLOCV_N(VALUE, argbuf, argc+1); VALUE argbuf, *new_args = ALLOCV_N(VALUE, argbuf, argc+1);
new_args[0] = ID2SYM(mid); new_args[0] = ID2SYM(mid);
#ifdef __GLIBC__
if (!argv) {
static const VALUE buf = Qfalse;
VM_ASSERT(argc == 0);
argv = &buf;
}
#endif
MEMCPY(new_args+1, argv, VALUE, argc); MEMCPY(new_args+1, argv, VALUE, argc);
ec->method_missing_reason = MISSING_NOENTRY; ec->method_missing_reason = MISSING_NOENTRY;
args.ec = ec; args.ec = ec;
@ -734,6 +741,13 @@ method_missing(VALUE obj, ID id, int argc, const VALUE *argv, enum method_missin
nargv = ALLOCV_N(VALUE, work, argc + 1); nargv = ALLOCV_N(VALUE, work, argc + 1);
nargv[0] = ID2SYM(id); nargv[0] = ID2SYM(id);
#ifdef __GLIBC__
if (!argv) {
static const VALUE buf = Qfalse;
VM_ASSERT(argc == 0);
argv = &buf;
}
#endif
MEMCPY(nargv + 1, argv, VALUE, argc); MEMCPY(nargv + 1, argv, VALUE, argc);
++argc; ++argc;
argv = nargv; argv = nargv;