Hi, Chris,

On Friday, 7. December 2007, Chris Dukes wrote:
> Version 0.17 of _wrap is as follows
>
> sub _wrap {
>   my $len=$_[1];
>   return $_[0] if length($_[0]) <= $len;
>   use integer;
>   my $l2 = $len-1;
>   my $x = (length($_[0]) - $len) / $l2;
>   my $extra = (length($_[0]) == ($l2 * $x + $len)) ? "" : "a*";
>   join("\n ",unpack("a$len" . "a$l2" x $x . $extra,$_[0]));
> }
>
> Unfortunately it does not behave as documented and actually throws
> a division by zero error if wrap is set to 1.
>
> This version corrects it as documented.  Replace '40' with '2'
> and everything works including the most pathological case.
>
> sub _wrap {
>   my $len=$_[1];
>   return $_[0] if $len <= 40;
>   return $_[0] if length($_[0]) <= $len;
>   use integer;
>   my $l2 = $len-1;
>   my $x = (length($_[0]) - $len) / $l2;
>   my $extra = (length($_[0]) == ($l2 * $x + $len)) ? "" : "a*";
>   join("\n ",unpack("a$len" . "a$l2" x $x . $extra,$_[0]));
> }

Thanks for thebug report.

I fixed it in perl-ldap's SVN repository with a similar patch.

CU
Peter


-- 
Peter Marschall
[EMAIL PROTECTED]

Reply via email to