summaryrefslogtreecommitdiff
path: root/ext/dbm
diff options
context:
space:
mode:
Diffstat (limited to 'ext/dbm')
-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);