Subject: | DBM::Deep hates "0" for a key |
You will find a smallish patch attached that fixes a problem when
iterating over keys that might include a "0". I.e., if you do this:
$db->{'0'} = 'foo';
my @keys = keys %$db;
the program will deadlock because of an if-statement that needs a defined().
Subject: | dbm-deep-hates-zero.patch |
From 99e7e4a783fa20b3a84bd9e92bbe1161e9751a80 Mon Sep 17 00:00:00 2001
From: Sterling Hanenkamp <hanenkamp@cpan.org>
Date: Sun, 9 Nov 2008 15:53:19 -0600
Subject: [PATCH] Adding a failing test for zero keys
---
t/54_zero.t | 20 ++++++++++++++++++++
1 files changed, 20 insertions(+), 0 deletions(-)
create mode 100644 t/54_zero.t
diff --git a/t/54_zero.t b/t/54_zero.t
new file mode 100644
index 0000000..9d2f457
--- /dev/null
+++ b/t/54_zero.t
@@ -0,0 +1,20 @@
+use strict;
+use Test::More tests => 2;
+use t::common qw( new_fh );
+
+use_ok( 'DBM::Deep' );
+
+my ($fh, $filename) = new_fh();
+my $db = DBM::Deep->new(
+ file => $filename,
+ fh => $fh,
+);
+
+$db->{'0'} = 'test';
+
+my %temphash;
+while (my ($key, $value) = each %$db) {
+ $temphash{$key} = $value;
+}
+
+is($temphash{'0'}, 'test', 'copied with key 0');
--
1.6.0.2
From c66c37503cfe019d97308add070d6a524ad11236 Mon Sep 17 00:00:00 2001
From: Sterling Hanenkamp <hanenkamp@cpan.org>
Date: Sun, 9 Nov 2008 16:03:41 -0600
Subject: [PATCH] Correct deadlock if key "0" is stored
---
lib/DBM/Deep/Engine.pm | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/DBM/Deep/Engine.pm b/lib/DBM/Deep/Engine.pm
index 1df77fd..36cc645 100644
--- a/lib/DBM/Deep/Engine.pm
+++ b/lib/DBM/Deep/Engine.pm
@@ -387,7 +387,7 @@ sub get_next_key {
my ($obj, $prev_key) = @_;
# XXX Need to add logic about resetting the iterator if any key in the reference has changed
- unless ( $prev_key ) {
+ unless ( defined $prev_key ) {
$obj->{iterator} = DBM::Deep::Iterator->new({
base_offset => $obj->_base_offset,
engine => $self,
--
1.6.0.2