Skip Menu |

This queue is for tickets about the Net-DHCP CPAN distribution.

Report information
The Basics
Id: 20410
Status: resolved
Priority: 0/
Queue: Net-DHCP

People
Owner: Nobody in particular
Requestors: Nathan.Scarlett [...] alcatel.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Subject: method "removeOption" corrupts the option_order index array
Stephan, I believe I've found a bug in the Net::DHCP::Packet.pm CPAN module. I'm using version 0.65. The removeOption method is not working. I've attempted to correct the problem. Here's my suggested fix: Show quoted text
> sub removeOption { > my ($self,$key) = @_; > if (exists($self->{options}->{$key})) { > my $i; > for ($i = 0; $i < @{$self->{options_order}}; $i++) { > last if ($self->{options_order}->[$i] == $key); #added "== $key" > } > if ($i < @{$self->{options_order}}) { > #delete ($self->{options_order}->[$i]);#commented out this line > splice @{$self->{options_order}},$i,1;#added this line > } > delete ($self->{options}->{$key}); > } > }
With the original code, the "last" statement was performed as soon as the first non-zero $key was reached in the array reference $self->{options_order}. I added the test operator "== $key". Also, if the function "delete" is used on an index in the middle of an array, the array element is not destroyed, it's just set to undefined. I used the function splice instead, to be sure that the selected element of the array was removed, and the array is shortened. I'm running perl 5.8.7 on cygwin. I hope this is helpful. Nathan Scarlett
hi nathan, i agree with the principles of your fix. however slicing the array like that will have perl copy the whole data structure around in memory. instead ill use the splice function, which nicely has perl itseld rip out an array element
On Wed Nov 24 05:34:46 2010, djzort wrote: Show quoted text
> hi nathan, i agree with the principles of your fix. however slicing the > array like that will have perl copy the whole data structure around in > memory. > > instead ill use the splice function, which nicely has perl itseld rip > out an array element
wait, take that back :) your change has already been applied previously
On Wed Nov 24 05:37:54 2010, djzort wrote: Show quoted text
> On Wed Nov 24 05:34:46 2010, djzort wrote:
> > hi nathan, i agree with the principles of your fix. however slicing the > > array like that will have perl copy the whole data structure around in > > memory. > > > > instead ill use the splice function, which nicely has perl itseld rip > > out an array element
> > wait, take that back :) > > your change has already been applied previously
anyway, ive swapped out the for-counter with a first {} 1..$#array