# \[Bug:1.8\] RSTRING in ext/gdbm/gdbm.c

**URL:** <https://www.ruby-forum.com/t/bug-1-8-rstring-in-ext-gdbm-gdbm-c/154087>\
**Category:** Development\
**Created:** [November 25, 2008, 8:02am UTC](https://www.ruby-forum.com/t/bug-1-8-rstring-in-ext-gdbm-gdbm-c/154087 "2008-11-25T08:02:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kazuhiro\_NISHIYAMA](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/77aa72/32.png) [@Kazuhiro\_NISHIYAMA](https://www.ruby-forum.com/u/Kazuhiro_NISHIYAMA)\
**Post date:** [November 25, 2008, 8:02am UTC](https://www.ruby-forum.com/t/bug-1-8-rstring-in-ext-gdbm-gdbm-c/154087/1 "2008-11-25T08:02:14Z")

</div>

e$B@\>;3OB9-$G$9!#e(B

[ruby-core:20082]e$B$K$R$C$+$+$C$?$N$G!"$H$j$"$($:e(B

# Index: object.c

— object.c(revision 20352)  
+++ object.c(working copy)  
@@ -223,7 +223,7 @@  
}  
clone = rb\_obj\_alloc(rb\_obj\_class(obj));  
RBASIC(clone)-\>klass = rb\_singleton\_class\_clone(obj);

- RBASIC(clone)-\>flags = (RBASIC(obj)-\>flags | FL\_TEST(clone,  
FL\_TAINT)) & ~(FL\_FREEZE|FL\_FINALIZE);

- RBASIC(clone)-\>flags = (RBASIC(obj)-\>flags | FL\_TEST(clone,  
FL\_TAINT|ELTS\_SHARED)) & ~(FL\_FREEZE|FL\_FINALIZE);  
init\_copy(clone, obj);  
RBASIC(clone)-\>flags |= RBASIC(obj)-\>flags & FL\_FREEZE;

e$B$H$7$F2sHr$7$F$_$?$H$3$m!"e(Bgdbme$B$N%F%9%H$NCf$GMn$A$k$h$&$K$J$C$?$N$G!"e(B  
e$BD4$Y$F$_$?$H$3$m!“e(Brb\_str\_s\_alloce$B$Ge(BELTS\_SHAREDe$B$,@\_Dj$5$l$F$$$k$N$Ke(B  
aux.sharede$B$rL5;k$7$Fe(Baux.capae$B$r@\_Dj$7$F$$$F!”$=$l$r8e$Ge(B  
RSTRING(aux.shared)e$B$G;2\>H$5$l$F$7$^$&$N$,860x$@$H$o$+$j$^$7$?!#e(B

e$B0J2\<$N$h$&$K$7$?J}$,NI$$$H;W$C$?$N$G$9$,!"$I$&$G$7$g$&$+e(B?

# Index: ext/gdbm/gdbm.c

— ext/gdbm/gdbm.c(revision 20352)  
+++ ext/gdbm/gdbm.c(working copy)  
@@ -303,12 +303,7 @@  
if (val.dptr == 0)  
return Qnil;

- str = rb\_obj\_alloc(rb\_cString);
- RSTRING(str)-\>len = val.dsize;
- RSTRING(str)-\>aux.capa = val.dsize;
- RSTRING(str)-\>ptr = REALLOC\_N(val.dptr,char,val.dsize+1);
- RSTRING(str)-\>ptr[val.dsize] = ‘\0’;
- 

- str = rb\_str\_new(val.dptr, val.dsize);  
OBJ\_TAINT(str);  
return (VALUE)str;  
}  
@@ -349,12 +344,7 @@  
if (key.dptr == 0)  
return Qnil;

- str = rb\_obj\_alloc(rb\_cString);
- RSTRING(str)-\>len = key.dsize;
- RSTRING(str)-\>aux.capa = key.dsize;
- RSTRING(str)-\>ptr = REALLOC\_N(key.dptr,char,key.dsize+1);
- RSTRING(str)-\>ptr[RSTRING(str)-\>len] = ‘\0’;
- 

- str = rb\_str\_new(key.dptr, key.dsize);  
OBJ\_TAINT(str);  
return str;  
}  
@@ -373,12 +363,7 @@  
if (key2.dptr == 0)  
return Qnil;

- str = rb\_obj\_alloc(rb\_cString);
- RSTRING(str)-\>len = key2.dsize;
- RSTRING(str)-\>aux.capa = key2.dsize;
- RSTRING(str)-\>ptr = REALLOC\_N(key2.dptr,char,key2.dsize+1);
- RSTRING(str)-\>ptr[RSTRING(str)-\>len] = ‘\0’;
- 

- str = rb\_str\_new(key2.dptr, key2.dsize);  
OBJ\_TAINT(str);  
return str;  
}

---

<div class="post-metadata">

**Author:** ![Kazuhiro\_NISHIYAMA](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/77aa72/32.png) [@Kazuhiro\_NISHIYAMA](https://www.ruby-forum.com/u/Kazuhiro_NISHIYAMA)\
**Post date:** [November 25, 2008, 9:01am UTC](https://www.ruby-forum.com/t/bug-1-8-rstring-in-ext-gdbm-gdbm-c/154087/2 "2008-11-25T09:01:55Z")

</div>

e$B@\>;3OB9-$G$9!#e(B

e$B@h$[$I$N%Q%C%A$G$Oe(Bdptre$B$,%a%b%j%j!\<%/$9$k$h$&$K$J$C$F$7$^$C$F$$$?$N$G!"e(B  
e$B=$@5$7$^$7$?!#e(B

# Index: ext/gdbm/gdbm.c

— ext/gdbm/gdbm.c(revision 20353)  
+++ ext/gdbm/gdbm.c(working copy)  
@@ -303,14 +303,10 @@  
if (val.dptr == 0)  
return Qnil;

- str = rb\_obj\_alloc(rb\_cString);
- RSTRING(str)-\>len = val.dsize;
- RSTRING(str)-\>aux.capa = val.dsize;
- RSTRING(str)-\>ptr = REALLOC\_N(val.dptr,char,val.dsize+1);
- RSTRING(str)-\>ptr[val.dsize] = ‘\0’;
- 

- str = rb\_str\_new(val.dptr, val.dsize);  
OBJ\_TAINT(str);

- return (VALUE)str;

- free(val.dptr);
- return str;  
}

static VALUE  
@@ -349,13 +345,9 @@  
if (key.dptr == 0)  
return Qnil;

- str = rb\_obj\_alloc(rb\_cString);
- RSTRING(str)-\>len = key.dsize;
- RSTRING(str)-\>aux.capa = key.dsize;
- RSTRING(str)-\>ptr = REALLOC\_N(key.dptr,char,key.dsize+1);
- RSTRING(str)-\>ptr[RSTRING(str)-\>len] = ‘\0’;
- 

- str = rb\_str\_new(key.dptr, key.dsize);  
OBJ\_TAINT(str);
- free(key.dptr);  
return str;  
}

@@ -373,13 +365,9 @@  
if (key2.dptr == 0)  
return Qnil;

- str = rb\_obj\_alloc(rb\_cString);
- RSTRING(str)-\>len = key2.dsize;
- RSTRING(str)-\>aux.capa = key2.dsize;
- RSTRING(str)-\>ptr = REALLOC\_N(key2.dptr,char,key2.dsize+1);
- RSTRING(str)-\>ptr[RSTRING(str)-\>len] = ‘\0’;
- 

- str = rb\_str\_new(key2.dptr, key2.dsize);  
OBJ\_TAINT(str);
- free(key2.dptr);  
return str;  
}

---

<div class="post-metadata">

**Author:** ![Kazuhiro\_NISHIYAMA](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/77aa72/32.png) [@Kazuhiro\_NISHIYAMA](https://www.ruby-forum.com/u/Kazuhiro_NISHIYAMA)\
**Post date:** [November 26, 2008, 5:37am UTC](https://www.ruby-forum.com/t/bug-1-8-rstring-in-ext-gdbm-gdbm-c/154087/3 "2008-11-26T05:37:37Z")

</div>

e$B%A%1%C%He(B #789 e$B$,99?7$5$l$^$7$?!#e(B (by Anonymous)

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 r20361.

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