refining an empty pathz would cause a segfault
authorDiane Trout <diane@caltech.edu>
Thu, 2 Mar 2006 22:36:58 +0000 (22:36 +0000)
committerDiane Trout <diane@caltech.edu>
Thu, 2 Mar 2006 22:36:58 +0000 (22:36 +0000)
So I added the test code to check for that condition and not run the
refining code (especially the initialization of our first extended
window pointer which was the real culprit).

alg/nway_paths.cxx

index 69184b55ab7483eab8f22c58fc7cc0f901bf29e6..bd6befd230fc401bfc93bedef8135baacd9e0b58 100644 (file)
@@ -60,42 +60,47 @@ NwayPaths::simple_refine()
 
   cout << "path number is: " << pathz.size() << endl;
   pathz_i = pathz.begin();
-  ext_path = ExtendedConservedPath( win_size, *pathz_i);
 
-  while(pathz_i != pathz.end())
+  // only try to extend when pathz isn't empty.
+  if (pathz_i != pathz.end())
   {
-    // keep track of current path and advance to next path
-    cur_path = pathz_i;
-    ++pathz_i;
-    if (pathz_i == pathz.end())
-      end = true;
-    else
-      next_path = pathz_i;
-
-    if (not end)
-    {
-      // if node for each seq is equal to the next node+1 then for all
-      // sequences then we are extending
-      extending = cur_path->nextTo(*next_path);
-    }
-    else
-      extending = false;
+    ext_path = ExtendedConservedPath( win_size, *pathz_i);
 
-    if (extending)
-    {
-      //cout << "Raaaawwwrrr!  I am extending\n";
-      win_ext_len++;
-    }
-    else
+    while(pathz_i != pathz.end())
     {
-      // add the extend window length as first element and add as refined
-      // now that we have the path to extend save it
-      new_path = ext_path;
-      new_path.extend(win_ext_len);
-      refined_pathz.push_back(new_path);
-      // reset stuff
-      win_ext_len = 0;
-      ext_path = ExtendedConservedPath( win_size, *next_path);
+      // keep track of current path and advance to next path
+      cur_path = pathz_i;
+      ++pathz_i;
+      if (pathz_i == pathz.end())
+        end = true;
+      else
+        next_path = pathz_i;
+
+      if (not end)
+      {
+        // if node for each seq is equal to the next node+1 then for all
+        // sequences then we are extending
+        extending = cur_path->nextTo(*next_path);
+      }
+      else
+        extending = false;
+  
+      if (extending)
+      {
+        //cout << "Raaaawwwrrr!  I am extending\n";
+        win_ext_len++;
+      }
+      else
+      {
+        // add the extend window length as first element and add as refined
+        // now that we have the path to extend save it
+        new_path = ext_path;
+        new_path.extend(win_ext_len);
+        refined_pathz.push_back(new_path);
+        // reset stuff
+        win_ext_len = 0;
+        ext_path = ExtendedConservedPath( win_size, *next_path);
+      }
     }
   }
   cout << "r_path number is: " << refined_pathz.size() << endl;