Subject: | hexdump() fails if length of data is 1 |
I've been bitten by this a bunch of times now, and just didn't find
the time to report it... :-(
When calling hexdump() with a single byte of data, it will fail with
the following error:
mhx@r2d2 ~ $ perl -MData::Hexdumper -e'print hexdump(data => "1")'
end_position must be after start position. at
/usr/lib/perl5/vendor_perl/5.8.8/Data/Hexdumper.pm line 145.
But since the (default) end_position is length(data)-1, it doesn't
have to be after start_position, but it must not be *before*
start_position.
The fix is trivial and a patch including a test case and a typo fix
is attached. :-)
(BTW, the module won't work with vanilla perls <5.6.0 due to the
"use warnings". So the tests might just as well "use Test", just
in case they were written that way for backwards compatibility.)
Marcus
Subject: | data-hexdumper.diff |
diff -ruN Data-Hexdumper-1.2/lib/Data/Hexdumper.pm Data-Hexdumper-1.2-mhx/lib/Data/Hexdumper.pm
--- Data-Hexdumper-1.2/lib/Data/Hexdumper.pm 2004-02-18 14:04:45.000000000 +0100
+++ Data-Hexdumper-1.2-mhx/lib/Data/Hexdumper.pm 2007-08-17 12:50:15.000000000 +0200
@@ -142,8 +142,8 @@
$end_position ||= length($data)-1;
die("end_position must be numeric.") if($end_position=~/\D/);
- die("end_position must be after start position.")
- if($end_position <= $start_position);
+ die("end_position must not be before start_position.")
+ if($end_position < $start_position);
# extract the required range and pad end with NULLs if necessary
diff -ruN Data-Hexdumper-1.2/test.pl Data-Hexdumper-1.2-mhx/test.pl
--- Data-Hexdumper-1.2/test.pl 2004-02-20 13:55:08.000000000 +0100
+++ Data-Hexdumper-1.2-mhx/test.pl 2007-08-17 12:54:41.000000000 +0200
@@ -1,7 +1,7 @@
use strict; use warnings;
my $loaded;
-BEGIN { $| = 1; print "1..9\n"; }
+BEGIN { $| = 1; print "1..10\n"; }
END { print "not ok 1\n" unless $loaded; }
use Data::Hexdumper;
@@ -130,3 +130,10 @@
0x0010 : 3031 3233 3435 3637 3839 3A3B 3C3D 3E00 : 0123456789:;<=>.
});
print 'ok '.++$test."\n";
+
+$results = hexdump(data => '!');
+print "not " unless($results eq <<'DUMP');
+ 0x0000 : 21 : !
+DUMP
+print 'ok '.++$test."\n";
+