From 8144e7cf457215b28c39bc56243e344cbd5b1e60 Mon Sep 17 00:00:00 2001 From: KRKeegan Date: Thu, 17 Jan 2013 15:16:47 -0800 Subject: [PATCH] get_first_empty_address should return 0 if no addr The sub add_link expects get_first_empty_address to return 0 if no empty address is found. This will prevent trying to add an aldb record to the FFFFFFFFFFFFFFF8 address which clearly doesn't exist. Instead the user will now get a nice error advising them to scan the link table before trying to sync links. It appears that something about Marc Merlin or my changes have some difference in the line endings. Not sure why the additional lines are listed as changed. --- lib/Insteon/AllLinkDatabase.pm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Insteon/AllLinkDatabase.pm b/lib/Insteon/AllLinkDatabase.pm index 2759ae48c..3e80c8bc3 100755 --- a/lib/Insteon/AllLinkDatabase.pm +++ b/lib/Insteon/AllLinkDatabase.pm @@ -1219,9 +1219,9 @@ sub add_duplicate_link_address sub delete_duplicate_link_address { my ($self, $address) = @_; - my $num_duplicate_link_addresses = 0; - - $num_duplicate_link_addresses = @{$$self{aldb}{duplicates}} if (defined $$self{aldb}{duplicates}); + my $num_duplicate_link_addresses = 0; + + $num_duplicate_link_addresses = @{$$self{aldb}{duplicates}} if (defined $$self{aldb}{duplicates}); if ($num_duplicate_link_addresses) { my @temp_duplicates = (); @@ -1241,8 +1241,8 @@ sub add_empty_address { my ($self, $address) = @_; # before adding it, make sure that it isn't already in the list!! - my $num_addresses = 0; - $num_addresses = @{$$self{aldb}{empty}} if (defined $$self{aldb}{empty}); + my $num_addresses = 0; + $num_addresses = @{$$self{aldb}{empty}} if (defined $$self{aldb}{empty}); my $exists = 0; if ($num_addresses and $address) { @@ -1298,7 +1298,7 @@ sub get_first_empty_address $low_address = $new_address if $new_address < $low_address; } } - $first_address = sprintf('%04X', $low_address - 8); + $first_address = ($low_address > 0) ? sprintf('%04X', $low_address - 8) : 0; } return $first_address;