summaryrefslogtreecommitdiff
path: root/ext/gdbm/gdbm.c
diff options
context:
space:
mode:
authorkazu <kazu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-11-26 04:33:16 +0000
committerkazu <kazu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-11-26 04:33:16 +0000
commit2fa77408140189eb09a9da4d17e7cc5d582c8234 (patch)
treec7289cec9ed5bad31a45f9498bbcba3e1dc36079 /ext/gdbm/gdbm.c
parentd5a75a355090971040f941e9c1cfaa7ea34c5513 (diff)
* ext/gdbm/gdbm.c: do not set members of RSTRING(str) directly.
[ruby-dev:37182] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@20361 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/gdbm/gdbm.c')
-rw-r--r--ext/gdbm/gdbm.c26
1 files changed, 7 insertions, 19 deletions
diff --git a/ext/gdbm/gdbm.c b/ext/gdbm/gdbm.c
index cf276e4db9..30a282c9c3 100644
--- a/ext/gdbm/gdbm.c
+++ b/ext/gdbm/gdbm.c
@@ -303,14 +303,10 @@ rb_gdbm_fetch(dbm, key)
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);
+ free(val.dptr);
OBJ_TAINT(str);
- return (VALUE)str;
+ return str;
}
static VALUE
@@ -349,12 +345,8 @@ rb_gdbm_firstkey(dbm)
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);
+ free(key.dptr);
OBJ_TAINT(str);
return str;
}
@@ -373,12 +365,8 @@ rb_gdbm_nextkey(dbm, keystr)
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);
+ free(key2.dptr);
OBJ_TAINT(str);
return str;
}