# \[Bug #1452\] DL::CPtr.new doesn't check the type of the 3rd arg

**URL:** <https://www.ruby-forum.com/t/bug-1452-dl-cptr-new-doesnt-check-the-type-of-the-3rd-arg/167602>\
**Category:** Development\
**Created:** [May 10, 2009, 2:37am UTC](https://www.ruby-forum.com/t/bug-1452-dl-cptr-new-doesnt-check-the-type-of-the-3rd-arg/167602 "2009-05-10T02:37:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Takashi\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/4af34b/32.png) [@Takashi\_T](https://www.ruby-forum.com/u/Takashi_T)\
**Post date:** [May 10, 2009, 2:37am UTC](https://www.ruby-forum.com/t/bug-1452-dl-cptr-new-doesnt-check-the-type-of-the-3rd-arg/167602/1 "2009-05-10T02:37:14Z")

</div>

Bug #1452: DL::CPtr.new doesn’t check the type of the 3rd arg.  
[http://redmine.ruby-lang.org/issues/show/1452](http://redmine.ruby-lang.org/issues/show/1452)

e$B5/I\<\<Te(B: Takashi T.  
e$B%9%F!\<%?%9e(B: Open, e$BM%@hEYe(B: Normal  
e$B%+%F%4%je(B: ext, Target version: 1.9.2  
ruby -v: ruby 1.9.2dev (2009-05-02 trunk 23326) [i686-linux]

DL::CPtr.new  
e$B$,0z?t$N7?$r%A%'%C%/$;$:$$$-$J$j9=B$BN$X%-%c%9%H$7$F$^$9!#e(B  
e$B%Q%C%A$G$9!#e(B

# $ svn diff cptr.c Index: cptr.c

— cptr.c (e$B%j%S%8%g%se(B 23328)  
+++ cptr.c (e$B:n6H%3%T!\<e(B)  
@@ -109,6 +109,7 @@ rb\_dlptr\_initialize(int argc, VALUE argv  
{  
VALUE ptr, sym, size;  
struct ptr\_data \*data;

- extern VALUE rb\_cDLCFunc;  
void _p = NULL;  
freefunc\_t f = NULL;  
long s = 0;  
@@ -124,7 +125,15 @@ rb\_dlptr\_initialize(int argc, VALUE argv  
case 3:  
p = (void_)(NUM2PTR(rb\_Integer(ptr)));  
s = NUM2LONG(size);

- f = NIL\_P(sym) ? NULL : RCFUNC\_DATA(sym)-\>ptr;

- if (NIL\_P(sym)) {
- 

```
 f = NULL;

```

- }
- else if (rb\_obj\_is\_kind\_of(sym, rb\_cDLCFunc) == Qtrue ){
- 

```
 f = RCFUNC_DATA(sym)->ptr;

```

- }
- else {
- 

```
 f = NUM2PTR(rb_Integer(sym));

```

- }  
break;  
default:  
rb\_bug(“rb\_dlptr\_initialize”);

---

<div class="post-metadata">

**Author:** ![Takashi\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/4af34b/32.png) [@Takashi\_T](https://www.ruby-forum.com/u/Takashi_T)\
**Post date:** [May 10, 2009, 4:18am UTC](https://www.ruby-forum.com/t/bug-1452-dl-cptr-new-doesnt-check-the-type-of-the-3rd-arg/167602/2 "2009-05-10T04:18:03Z")

</div>

e$B%A%1%C%He(B #1452 e$B$,99?7$5$l$^$7$?!#e(B (by Nobuyoshi N.)

e$B%9%F!\<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B  
e$B?JD=e(B % 0e$B$+$ie(B100e$B$KJQ99e(B

## Applied in changeset r23385.

[http://redmine.ruby-lang.org/issues/show/1452](http://redmine.ruby-lang.org/issues/show/1452)
