[Avida-SVN] r3386 - development/source/main

charles at myxo.css.msu.edu charles at myxo.css.msu.edu
Wed Aug 26 09:29:27 PDT 2009


Author: charles
Date: 2009-08-26 12:29:27 -0400 (Wed, 26 Aug 2009)
New Revision: 3386

Modified:
   development/source/main/cGenomeUtil.cc
Log:
Fixed assert problem with FindEditDistance in cGenomeUtil.cc.  This fix should not change any functionality.


Modified: development/source/main/cGenomeUtil.cc
===================================================================
--- development/source/main/cGenomeUtil.cc	2009-08-26 15:06:33 UTC (rev 3385)
+++ development/source/main/cGenomeUtil.cc	2009-08-26 16:29:27 UTC (rev 3386)
@@ -175,14 +175,16 @@
 {
   const int size1 = gen1.GetSize();
   const int size2 = gen2.GetSize();
+  const int min_size = min(size1, size2);
 
-  if (!size1) return size2;
-  if (!size2) return size1;
+  // If either size is zero, return the other one!
+  if (!min_size) return max(size1, size2);
 
   // Count how many direct matches we have at the front and end.
   int match_front = 0, match_end = 0;
-  while (gen1[match_front] == gen2[match_front]) match_front++;
-  while (gen1[size1 - match_end - 1] == gen2[size2 - match_end - 1]) match_end++;
+  while (match_front < min_size && gen1[match_front] == gen2[match_front]) match_front++;
+  while (match_end < min_size &&
+	 gen1[size1 - match_end - 1] == gen2[size2 - match_end - 1]) match_end++;
 
   // We can ignore the last match_end sites since we know they have distance zero.
   const int test_size1 = size1 - match_front - match_end;




More information about the Avida-cvs mailing list