perl-unicode

[PATCH] Let Guess.pm handles uninitialized argument.

2002-05-01 05:19:33
This way is self-descriptory; it makes -w happier. :)

/Autrijus/

--- /home/autrijus/perl/ext/Encode/lib/Encode/Guess.pm  Fri Apr 26 11:40:12 2002
+++ 
/usr/local/lib/perl5/site_perl/5.7.3/i386-freebsd-thread-multi/Encode/Guess.pm  
    Wed May  1 19:34:06 2002
@@ -69,16 +69,20 @@
     my $class = shift;
     my $obj   = ref($class) ? $class : $Encode::Encoding{$Canon};
     my $octet = shift;
+
+    # sanity check
+    return unless defined $octet and length $octet;
+
     # cheat 0: utf8 flag;
     Encode::is_utf8($octet) and return find_encoding('utf8');
     # cheat 1: BOM
     use Encode::Unicode;
     my $BOM = unpack('n', $octet);
     return find_encoding('UTF-16') 
-       if ($BOM == 0xFeFF or $BOM == 0xFFFe);
+       if (defined $BOM and ($BOM == 0xFeFF or $BOM == 0xFFFe));
     $BOM = unpack('N', $octet);
     return find_encoding('UTF-32') 
-       if ($BOM == 0xFeFF or $BOM == 0xFFFe0000);
+       if (defined $BOM and ($BOM == 0xFeFF or $BOM == 0xFFFe0000));
 
     my %try =  %{$obj->{Suspects}};
     for my $c (@_){

Attachment: pgp0I5pbTrfWG.pgp
Description: PGP signature

<Prev in Thread] Current Thread [Next in Thread>