Author: sidney
Date: Wed Aug 19 00:42:00 2026
New Revision: 1937215
Log:
Bug 8409 - Fix ReturnUndef Perlcritic warnings where safe
Suppress the warning where it cannot be proven safe to change the return
See bug 8409 comments and attachments for details
Github: closes #37
Modified:
spamassassin/trunk/lib/Mail/SpamAssassin/Conf/Parser.pm
spamassassin/trunk/lib/Mail/SpamAssassin/GeoDB.pm
spamassassin/trunk/lib/Mail/SpamAssassin/Handler/Archive.pm
spamassassin/trunk/lib/Mail/SpamAssassin/Handler/Image.pm
spamassassin/trunk/lib/Mail/SpamAssassin/Handler/PDF.pm
spamassassin/trunk/lib/Mail/SpamAssassin/PDF/Parser.pm
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Conf/Parser.pm
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Conf/Parser.pm Tue Aug 18 23:12:03 2026 (r1937214)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Conf/Parser.pm Wed Aug 19 00:42:00 2026 (r1937215)
@@ -1243,7 +1243,7 @@ sub pack_eval_args {
}
if ($args ne '') {
- return undef; ## no critic (ProhibitExplicitReturnUndef)
+ return;
}
return \@args;
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/GeoDB.pm
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/GeoDB.pm Tue Aug 18 23:12:03 2026 (r1937214)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/GeoDB.pm Wed Aug 19 00:42:00 2026 (r1937215)
@@ -750,7 +750,7 @@ sub get_dbinfo {
sub get_country {
my ($self, $ip) = @_;
- return undef if !defined $ip || $ip !~ /\S/; ## no critic (ProhibitExplicitReturnUndef)
+ return undef if !defined $ip || $ip !~ /\S/; ## no critic (ProhibitExplicitReturnUndef) - Bug 8409 - can't prove return; is safe here
if ($ip =~ IS_IP_PRIVATE) {
return '**';
@@ -766,14 +766,14 @@ sub get_country {
} elsif ($self->{dbapi}->{country}) {
return $self->_get('country',$ip)->{country} || 'XX';
} else {
- return undef; ## no critic (ProhibitExplicitReturnUndef)
+ return undef; ## no critic (ProhibitExplicitReturnUndef) - Bug 8409 - can't prove return; is safe here
}
}
sub get_continent {
my ($self, $ip) = @_;
- return undef if !defined $ip || $ip !~ /\S/; ## no critic (ProhibitExplicitReturnUndef)
+ return undef if !defined $ip || $ip !~ /\S/; ## no critic (ProhibitExplicitReturnUndef) - Bug 8409 - can't prove return; is safe here
# If it's already CC, use our own lookup table..
if (length($ip) == 2) {
@@ -785,66 +785,66 @@ sub get_continent {
} elsif ($self->{dbapi}->{country}) {
return $self->_get('country',$ip)->{continent} || 'XX';
} else {
- return undef; ## no critic (ProhibitExplicitReturnUndef)
+ return undef; ## no critic (ProhibitExplicitReturnUndef) - Bug 8409 - can't prove return; is safe here
}
}
sub get_isp {
my ($self, $ip) = @_;
- return undef if !defined $ip || $ip !~ /\S/; ## no critic (ProhibitExplicitReturnUndef)
+ return undef if !defined $ip || $ip !~ /\S/; ## no critic (ProhibitExplicitReturnUndef) - Bug 8409 - can't prove return; is safe here
if ($self->{dbapi}->{isp}) {
return $self->_get('isp',$ip)->{isp};
} else {
- return undef; ## no critic (ProhibitExplicitReturnUndef)
+ return undef; ## no critic (ProhibitExplicitReturnUndef) - Bug 8409 - can't prove return; is safe here
}
}
sub get_isp_org {
my ($self, $ip) = @_;
- return undef if !defined $ip || $ip !~ /\S/; ## no critic (ProhibitExplicitReturnUndef)
+ return undef if !defined $ip || $ip !~ /\S/; ## no critic (ProhibitExplicitReturnUndef) - Bug 8409 - can't prove return; is safe here
if ($self->{dbapi}->{isp}) {
return $self->_get('isp',$ip)->{organization};
} else {
- return undef; ## no critic (ProhibitExplicitReturnUndef)
+ return undef; ## no critic (ProhibitExplicitReturnUndef) - Bug 8409 - can't prove return; is safe here
}
}
sub get_asn {
my ($self, $ip) = @_;
- return undef if !defined $ip || $ip !~ /\S/; ## no critic (ProhibitExplicitReturnUndef)
+ return undef if !defined $ip || $ip !~ /\S/; ## no critic (ProhibitExplicitReturnUndef) - Bug 8409 - can't prove return; is safe here
if ($self->{dbapi}->{asn}) {
return $self->_get('asn',$ip)->{asn};
} elsif ($self->{dbapi}->{isp}) {
return $self->_get('isp',$ip)->{asn};
} else {
- return undef; ## no critic (ProhibitExplicitReturnUndef)
+ return undef; ## no critic (ProhibitExplicitReturnUndef) - Bug 8409 - can't prove return; is safe here
}
}
sub get_asn_org {
my ($self, $ip) = @_;
- return undef if !defined $ip || $ip !~ /\S/; ## no critic (ProhibitExplicitReturnUndef)
+ return undef if !defined $ip || $ip !~ /\S/; ## no critic (ProhibitExplicitReturnUndef) - Bug 8409 - can't prove return; is safe here
if ($self->{dbapi}->{asn}) {
return $self->_get('asn',$ip)->{asn_organization};
} elsif ($self->{dbapi}->{isp}) {
return $self->_get('isp',$ip)->{asn_organization};
} else {
- return undef; ## no critic (ProhibitExplicitReturnUndef)
+ return undef; ## no critic (ProhibitExplicitReturnUndef) - Bug 8409 - can't prove return; is safe here
}
}
sub get_all {
my ($self, $ip) = @_;
- return undef if !defined $ip || $ip !~ /\S/; ## no critic (ProhibitExplicitReturnUndef)
+ return undef if !defined $ip || $ip !~ /\S/; ## no critic (ProhibitExplicitReturnUndef) - Bug 8409 - can't prove return; is safe here
my $all = {};
@@ -897,7 +897,7 @@ sub name_to_ip {
return $ip;
}
dbg("geodb: failed to internally resolve $name");
- return undef; ## no critic (ProhibitExplicitReturnUndef)
+ return undef; ## no critic (ProhibitExplicitReturnUndef) - Bug 8409 - can't prove return; is safe here
}
sub _get {
@@ -912,7 +912,7 @@ sub _get {
if ($self->{dbapi}->{$type}) {
$self->{cache}{$ip}{$type} = $self->{dbapi}->{$type}->($self,$ip);
} else {
- return undef; ## no critic (ProhibitExplicitReturnUndef)
+ return;
}
}
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Handler/Archive.pm
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Handler/Archive.pm Tue Aug 18 23:12:03 2026 (r1937214)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Handler/Archive.pm Wed Aug 19 00:42:00 2026 (r1937215)
@@ -205,15 +205,15 @@ sub _basename {
sub _zip_entry_count {
my ($dataref) = @_;
my $len = defined $$dataref ? length $$dataref : 0;
- return undef if $len < 22;
+ return if $len < 22;
# Search backwards for the EOCD signature within the comment window. Scanning
# a bounded tail (not the whole file) keeps this cheap on large archives.
my $window = $len < 22 + 0xFFFF ? $len : 22 + 0xFFFF;
my $tail = substr($$dataref, $len - $window);
my $pos = rindex($tail, "PK\x05\x06");
- return undef if $pos < 0;
- return undef if $pos + 12 > length $tail; # not enough bytes for the count field
+ return if $pos < 0;
+ return if $pos + 12 > length $tail; # not enough bytes for the count field
my $count = unpack('v', substr($tail, $pos + 10, 2));
@@ -464,7 +464,7 @@ sub _run_unrar {
chomp(my $e = $err);
log_warn("unrar error: $e");
}
- return undef;
+ return;
}
return $resp;
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Handler/Image.pm
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Handler/Image.pm Tue Aug 18 23:12:03 2026 (r1937214)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Handler/Image.pm Wed Aug 19 00:42:00 2026 (r1937215)
@@ -408,7 +408,7 @@ sub _resolve_binary {
warn "image: $warn_msg\n" if defined $warn_msg;
dbg("image: $label not found, related conversions disabled")
if !defined $warn_msg;
- return undef;
+ return;
}
# Identify an image's real type and pixel dimensions from its leading bytes.
@@ -617,7 +617,7 @@ sub _ocr {
chomp(my $e = $err);
info("image: tesseract error: %s", $e);
}
- return undef;
+ return;
}
return $resp;
@@ -634,7 +634,7 @@ sub _heif_to_png {
my $convert = $self->_heif_convert($conf);
if (!$convert) {
dbg("image: cannot OCR HEIF, heif-convert not available");
- return undef;
+ return;
}
my $secs = $conf->{handler_time_limit} || 10;
@@ -718,7 +718,7 @@ sub _heif_to_png {
chomp(my $e = $err);
info("image: heif-convert error: %s", $e);
}
- return undef;
+ return;
}
# Return a ref to the converted bytes (handle_image threads it on by ref).
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Handler/PDF.pm
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Handler/PDF.pm Tue Aug 18 23:12:03 2026 (r1937214)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Handler/PDF.pm Wed Aug 19 00:42:00 2026 (r1937215)
@@ -439,7 +439,7 @@ sub _resolve_binary {
return $path;
}
log_dbg("$label not found, text extraction disabled (set pdf_pdftotext_path)");
- return undef;
+ return;
}
# _extract_text($pms, $dataref): run pdftotext on the decoded PDF bytes and
@@ -452,7 +452,7 @@ sub _extract_text {
my $conf = $pms->{conf} || $self->{main}->{conf};
my $bin = $self->_pdftotext($conf);
- return undef unless defined $bin;
+ return unless defined $bin;
my $pages = $conf->{pdf_text_max_pages};
$pages = DEFAULT_TEXT_MAX_PAGES unless defined $pages;
@@ -525,7 +525,7 @@ sub _extract_text {
chomp(my $e = $err);
log_warn("pdftotext error: $e");
}
- return undef;
+ return;
}
return $resp;
@@ -545,20 +545,20 @@ sub _extract_text {
sub _encode_image {
my ($self, $img) = @_;
my $bytes = $img->{bytes};
- return undef unless defined $bytes && length $bytes;
+ return unless defined $bytes && length $bytes;
my $format = $img->{format} // '';
return { type => 'image/jpeg', data => $bytes } if $format eq 'jpeg';
return { type => 'image/tiff', data => $bytes } if $format eq 'tiff';
- return undef unless $format eq 'raw';
+ return unless $format eq 'raw';
my $w = $img->{width};
my $h = $img->{height};
my $bpc = $img->{bpc};
my $cs = $img->{colorspace};
- return undef unless defined($w) && defined($h) && $w > 0 && $h > 0;
- return undef if ref($cs); # Indexed/ICCBased/etc. arrays - skip
+ return unless defined($w) && defined($h) && $w > 0 && $h > 0;
+ return if ref($cs); # Indexed/ICCBased/etc. arrays - skip
$cs = '' unless defined($cs);
my ($channels, $samples);
@@ -567,7 +567,7 @@ sub _encode_image {
# Bilevel: expand 1 bit/pixel (row byte-aligned) to 8-bit gray. PDF sample
# 0 = black, so bit 0 -> 0x00, bit 1 -> 0xff.
my $row_bytes = int(($w + 7) / 8);
- return undef if length($bytes) < $row_bytes * $h;
+ return if length($bytes) < $row_bytes * $h;
my $gray = '';
for my $y (0 .. $h-1) {
my $row = substr($bytes, $y * $row_bytes, $row_bytes);
@@ -577,22 +577,22 @@ sub _encode_image {
($channels, $samples) = (1, $gray);
}
elsif ( $cs =~ /rgb/i ) {
- return undef unless !defined($bpc) || $bpc == 8;
- return undef if length($bytes) < $w * $h * 3;
+ return unless !defined($bpc) || $bpc == 8;
+ return if length($bytes) < $w * $h * 3;
($channels, $samples) = (3, substr($bytes, 0, $w * $h * 3));
}
elsif ( $cs =~ /gray/i || $cs eq '' ) {
- return undef unless !defined($bpc) || $bpc == 8;
- return undef if length($bytes) < $w * $h;
+ return unless !defined($bpc) || $bpc == 8;
+ return if length($bytes) < $w * $h;
($channels, $samples) = (1, substr($bytes, 0, $w * $h));
}
else {
# CMYK / Separation / unknown - skip
- return undef;
+ return;
}
my $png = _raw_to_png($w, $h, $channels, $samples);
- return undef unless defined $png;
+ return unless defined $png;
return { type => 'image/png', data => $png };
}
@@ -609,7 +609,7 @@ sub _raw_to_png {
$raw .= "\x00" . substr($samples, $_ * $row_bytes, $row_bytes) for 0 .. $h-1;
my $idat = compress($raw);
- return undef unless defined $idat;
+ return unless defined $idat;
my $png = "\x89PNG\x0d\x0a\x1a\x0a";
$png .= _png_chunk('IHDR', pack('NNCCCCC', $w, $h, 8, $color_type, 0, 0, 0));
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/PDF/Parser.pm
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/PDF/Parser.pm Tue Aug 18 23:12:03 2026 (r1937214)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/PDF/Parser.pm Wed Aug 19 00:42:00 2026 (r1937215)
@@ -642,8 +642,8 @@ sub _get_obj {
my ($self,$ref) = @_;
my $core = $self->{core};
- # return undef for non-existent objects
- return undef unless defined($ref) && defined($self->{xref}->{$ref});
+ # return for non-existent objects
+ return unless defined($ref) && defined($self->{xref}->{$ref});
if ( !defined($self->{object_cache}->{$ref}) ) {
my ($objnum,$gennum) = $ref =~ /^(\d+) (\d+) R$/;
@@ -883,7 +883,7 @@ sub _ccitt_to_tiff {
my $w = $parms->{Columns};
my $h = $parms->{Rows};
- return undef unless defined($w) && defined($h) && $w > 0 && $h > 0;
+ return unless defined($w) && defined($h) && $w > 0 && $h > 0;
my $k = $parms->{K} || 0;
my ($compression, $t4options);
@@ -895,7 +895,7 @@ sub _ccitt_to_tiff {
# (T4Options bit 2). A Group 4 stream that sets it can't be described in TIFF,
# so decline rather than hand over data that would decode to garbage.
if ( $parms->{EncodedByteAlign} ) {
- return undef if $compression == 4;
+ return if $compression == 4;
$t4options |= 0x4;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.