Subject: | Possible bug in scan return |
I'm having a problem with the scan routine in File::Scan::ClamAV 1.06 when there is no virus detected. sub _scan_shallow returns undef to scan when there is no virus. The problem comes in when you try to return the first and second values from an non-existant arrayref. Would it not be better to test the array and return undef on an empty array like so?
[code]
sub scan {
my $self = shift;
$self->_seterrstr;
my @results;
if($self->{find_all}){
@results = $self->_scan('SCAN', @_);
} else {
@results = $self->_scan_shallow('SCAN', @_);
return unless @results; # return undef if @results is empty
return ($_->[0], $_->[1]);
}
my %f;
for(@results){
$f{ $_->[0] } = $_->[1];
}
return %f;
}
[/code]
Here is the test code I used:
[code]
#!/usr/bin/perl
use warnings;
use strict;
use File::Scan::ClamAV;
use Data::Dumper;
my $av = File::Scan::ClamAV->new();
if($av->ping) {
my %found = $av->scan('/path/to/file');
print Dumper(\%found);
}
[/code]
Which produces:
[results]
Use of uninitialized value in list assignment at ./test.pl line 9.
$VAR1 = {
'' => undef
};
[/results]
With the line I added I get this:
[results]
$VAR1 = {};
[/results]
[system info]
perl -v
This is perl, v5.8.1 built for i686-linux
uname - a
Linux 2.4.26-tfadmin #2 SMP Sun May 30 23:48:09 IST 2004 i686 i686 i386 GNU/Linux
[/system info]
Regards,
Charlie