From ee9f1463df43a75963a5f49497dab0a4d795d8f9 Mon Sep 17 00:00:00 2001 From: ttate Date: Thu, 29 Aug 2002 13:00:22 +0000 Subject: [PATCH] Merged Nakada's patch [ruby-dev:18097]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2765 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/dl/ptr.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ext/dl/ptr.c b/ext/dl/ptr.c index 149f33e4e5..21a703c24e 100644 --- a/ext/dl/ptr.c +++ b/ext/dl/ptr.c @@ -858,19 +858,21 @@ rb_dlptr_aset(int argc, VALUE argv[], VALUE self) if( TYPE(key) == T_FIXNUM || TYPE(key) == T_BIGNUM ){ void *dst, *src; - int len; - + long len; + StringValue(val); Data_Get_Struct(self, struct ptr_data, data); dst = (void*)((long)(data->ptr) + DLNUM2LONG(key)); src = RSTRING(val)->ptr; + len = RSTRING(val)->len; if( num == Qnil ){ - len = RSTRING(val)->len; + memcpy(dst, src, len); } else{ - len = NUM2INT(num); + long n = NUM2INT(num); + memcpy(dst, src, n < len ? n : len); + if( n > len ) MEMZERO((char*)dst + len, char, n - len); }; - memcpy(dst, src, len); return val; };