From 469be37439f7fdce91007e2afa1c216353c9374a Mon Sep 17 00:00:00 2001 From: Robert Ricci Date: Tue, 9 Nov 2010 15:00:29 -0700 Subject: [PATCH] Fix a bug in the reorderLinks() function Because it's operating on char*s, the STL list remove() function doesn't work; it needs to do a strcmp, not a simple comparison. So, hand-write the loop to do this. Also add a santity check to produce a fatal error rather than allowing this function to go into an infinite loop. --- assign/annotate_rspec_v2.cc | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/assign/annotate_rspec_v2.cc b/assign/annotate_rspec_v2.cc index 59763e7cd..6dbf42a81 100644 --- a/assign/annotate_rspec_v2.cc +++ b/assign/annotate_rspec_v2.cc @@ -687,8 +687,27 @@ annotate_rspec_v2::reorderLinks (list* links) prev = this->find_next_link_in_path(prev, links); string* link = new string(XStr(prev->getAttribute(XStr("component_id").x())).c()); - links->remove(link->c_str()); - ordered->push_back(link->c_str()); + + // Remove this link from the list - would rather use links->remove(), but + // it doesn't seem to be able to compare strings + list::iterator it; + bool found = false; + for (it = links->begin(); it != links->end(); it++) { + if (!strcmp(link->c_str(),*it)) { + found = true; + links->erase(it); + break; + } + } + + if (found) { + ordered->push_back(link->c_str()); + } else { + // Sanity check + cerr << "Error annotating link: couldn't find link (" << + link->c_str() << ")" << endl; + exit(EXIT_FATAL); + } } return ordered; -- GitLab