Skip Menu |

This queue is for tickets about the Expect CPAN distribution.

Report information
The Basics
Id: 36970
Status: open
Priority: 0/
Queue: Expect

People
Owner: Nobody in particular
Requestors: artrus [...] netzero.net
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.21
Fixed in: (no value)



Subject: Use of uninitialized value $indicate_truncation in concatenation (.) or string at Expect.pm line 1566 (patch included)
While it's not a critical bug but it's quite annoying to be flooded by such lines and the functionality isn't working a bit. "Use of uninitialized value $indicate_truncation in concatenation (.) or string at Expect.pm line 1566." To replicate, I have a file that I execute with Expect. The file produces a lot of output. My settings are: $exp->restart_timeout_upon_receive(1); $exp->log_file(\&exec_log_handler); $exp->max_accum(10_000); $exp->log_stdout(0); $exp->expect(60); The problem lies in the value from max_accum apparently not getting to the right place in this code: sub _trim_length { # This is sort of a reverse truncation function # Mostly so we don't have to see the full output when we're using # Also used if Max_Accum gets set to limit the size of the accumulator # for matching functions. # exp_internal my($self) = shift; my($string) = shift; my($length) = shift; # If we're not passed a length (_trim_length is being used for debugging # purposes) AND debug >= 3, don't trim. return($string) if (defined ($self) and ${*$self}{"exp_Debug"} >= 3 and (!(defined($length)))); my($indicate_truncation) = '...' unless $length; $length = 1021 unless $length; return($string) unless $length < length($string); # We wouldn't want the accumulator to begin with '...' if max_accum is passed # This is because this funct. gets called internally w/ max_accum # and is also used to print information back to the user. return $indicate_truncation.substr($string,(length($string) - $length),$length); <====== this is line 1566 } So looks like $indicate_truncation never gets initialized, because $length is passed in (10_000). A solution is to change it as there's no point setting the truncation string until the last return: sub _trim_length { # This is sort of a reverse truncation function # Mostly so we don't have to see the full output when we're using # Also used if Max_Accum gets set to limit the size of the accumulator # for matching functions. # exp_internal my($self) = shift; my($string) = shift; my($length) = shift; # If we're not passed a length (_trim_length is being used for debugging # purposes) AND debug >= 3, don't trim. return($string) if (defined ($self) and ${*$self}{"exp_Debug"} >= 3 and (!(defined($length)))); $length = 1021 unless $length; return($string) unless $length < length($string); # We wouldn't want the accumulator to begin with '...' if max_accum is passed # This is because this funct. gets called internally w/ max_accum # and is also used to print information back to the user. return '...'.substr($string,(length($string) - $length),$length); }
From: artrus [...] netzero.net
Actually, I just noticed your notes regarding not setting the '...'. In that case, a change would be to just make sure it's not undef. On Fri Jun 20 15:08:26 2008, Archon810 wrote: Show quoted text
> While it's not a critical bug but it's quite annoying to be flooded by > such lines and the functionality isn't working a bit. > > "Use of uninitialized value $indicate_truncation in concatenation (.) or > string at Expect.pm line 1566." > > To replicate, I have a file that I execute with Expect. The file > produces a lot of output. > > My settings are: > $exp->restart_timeout_upon_receive(1); > $exp->log_file(\&exec_log_handler); > $exp->max_accum(10_000); > $exp->log_stdout(0); > $exp->expect(60); > > The problem lies in the value from max_accum apparently not getting to > the right place in this code: > > sub _trim_length { > # This is sort of a reverse truncation function > # Mostly so we don't have to see the full output when we're using > # Also used if Max_Accum gets set to limit the size of the accumulator > # for matching functions. > # exp_internal > my($self) = shift; > my($string) = shift; > my($length) = shift; > > # If we're not passed a length (_trim_length is being used for debugging > # purposes) AND debug >= 3, don't trim. > return($string) if (defined ($self) and > ${*$self}{"exp_Debug"} >= 3 and (!(defined($length)))); > my($indicate_truncation) = '...' unless $length; > $length = 1021 unless $length; > return($string) unless $length < length($string); > # We wouldn't want the accumulator to begin with '...' if max_accum is > passed > # This is because this funct. gets called internally w/ max_accum > # and is also used to print information back to the user. > return $indicate_truncation.substr($string,(length($string) - > $length),$length); <====== this is line 1566 > } > > So looks like $indicate_truncation never gets initialized, because > $length is passed in (10_000). A solution is to change it as there's no > point setting the truncation string until the last return: > > sub _trim_length { > # This is sort of a reverse truncation function > # Mostly so we don't have to see the full output when we're using > # Also used if Max_Accum gets set to limit the size of the accumulator > # for matching functions. > # exp_internal > my($self) = shift; > my($string) = shift; > my($length) = shift; > > # If we're not passed a length (_trim_length is being used for debugging > # purposes) AND debug >= 3, don't trim. > return($string) if (defined ($self) and > ${*$self}{"exp_Debug"} >= 3 and (!(defined($length)))); > $length = 1021 unless $length; > return($string) unless $length < length($string); > # We wouldn't want the accumulator to begin with '...' if max_accum is > passed > # This is because this funct. gets called internally w/ max_accum > # and is also used to print information back to the user. > return '...'.substr($string,(length($string) - $length),$length); > }
Could you please check your code using 1.29 version of Expect? If it still generates the warnings, could you send an example?