diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | ext/gdbm/gdbm.c | 26 |
2 files changed, 12 insertions, 19 deletions
@@ -1,3 +1,8 @@ +Wed Nov 26 13:31:07 2008 Kazuhiro NISHIYAMA <[email protected]> + + * ext/gdbm/gdbm.c: do not set members of RSTRING(str) directly. + [ruby-dev:37182] + Tue Nov 25 16:09:36 2008 Nobuyoshi Nakada <[email protected]> * string.c (str_independent): no independent string points null_str. 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; } |