summaryrefslogtreecommitdiff
path: root/vm_eval.c
diff options
context:
space:
mode:
authorUrabe, Shyouhei <shyouhei@ruby-lang.org>2019-04-26 18:01:24 +0900
committerUrabe, Shyouhei <shyouhei@ruby-lang.org>2019-04-29 21:52:44 +0900
commite7b18ca6d9b45b7e71694557b9fab8152c62c1ed (patch)
treef6005283c9c0d362dd237f08328da47a144009df /vm_eval.c
parenta116f04ccabe8ce7d0e7312ef0f55f6a2cdd178e (diff)
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.
Diffstat (limited to 'vm_eval.c')
-rw-r--r--vm_eval.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/vm_eval.c b/vm_eval.c
index fc271415a6..285eb77773 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -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);
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);
ec->method_missing_reason = MISSING_NOENTRY;
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[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);
++argc;
argv = nargv;