summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-01 18:43:13 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-01 18:43:13 +0000
commite4518c5bde0f72723d784ba142df46df6407915b (patch)
treefb114dd39c18de64db2fc8c90faedace1db52f50 /ext
parentb66d7182b7030b1a69d6d72e0bc2e7b7cf7f8bb1 (diff)
dbm.c: yield dup of keystr
* ext/dbm/dbm.c (fdbm_fetch): yield dup of keystr, to make it shared and get rid of use of uninitialized variable. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44482 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/dbm/dbm.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/ext/dbm/dbm.c b/ext/dbm/dbm.c
index 1fdbaa0..03616fd 100644
--- a/ext/dbm/dbm.c
+++ b/ext/dbm/dbm.c
@@ -259,8 +259,11 @@ fdbm_fetch(VALUE obj, VALUE keystr, VALUE ifnone)
value = dbm_fetch(dbm, key);
if (value.dptr == 0) {
not_found:
- if (ifnone == Qnil && rb_block_given_p())
- return rb_yield(rb_tainted_str_new(key.dptr, key.dsize));
+ if (NIL_P(ifnone) && rb_block_given_p()) {
+ keystr = rb_str_dup(keystr);
+ OBJ_TAINT(keystr);
+ return rb_yield(keystr);
+ }
return ifnone;
}
return rb_tainted_str_new(value.dptr, value.dsize);