Subject: | bug: uninitialized value $code in substr warning |
Date: | Wed, 25 Sep 2013 11:11:20 -0400 (EDT) |
To: | bug-libnet [...] rt.cpan.org |
From: | Winston Wang <winston [...] rentec.com> |
Hello,
I'd like to report a minor bug, but one that I believe has a simple and
obvious fix. In Net/Cmd.pm, the response function ends with a call to:
substr($code,0,1);
However, the variable $code may be uninitialized. This is the source of
warnings I am getting in a script:
Use of uninitialized value $code in substr at
/usr/local/products/perl/5.16.0/lib/5.16.0/Net/Cmd.pm line 366.
Argument "" isn't numeric in numeric ne (!=) at
/usr/local/products/perl/5.16.0/Net/FTP.pm line 1082
My proposed fix is to modify this block of code:
($code,$more) = $cmd->parse_response($str);
unless(defined $code)
{
$cmd->ungetline($str);
last;
}
to become this:
($code,$more) = $cmd->parse_response($str);
unless(defined $code)
{
$cmd->ungetline($str);
return CMD_ERROR;
}
Returning here instead of breaking out of the loop avoids the substr()
call, and ensures that the function does not return undef, which will
prevent the warning message in Net/FTP.pm. Below is a patch for your
convenience.
Thank you very much for your time,
Winston
--- Cmd.pm.orig 2013-09-25 11:03:42.397090000 -0400
+++ Cmd.pm 2013-09-25 11:04:05.718207000 -0400
@@ -341,7 +341,7 @@
unless(defined $code)
{
$cmd->ungetline($str);
- last;
+ return CMD_ERROR;
}
${*$cmd}{'net_cmd_code'} = $code;