prekid programa sa greskom "signal 11"
29.03.2010. u 19:05 · pre 201 meseci
#1
Pokusavam da prepravim neki kod koji ce, umesto dosadasnje jedne promenjive nekog tipa, porediti listu pokazivaca tog tipa sa drugom promenjivom (istog tipa) i dalje izvrsavati program u zavisnosti od rezultata uslovne petlje. Kod je dat ispod sa definicijom tri metode koje pozivaju jedna drugu. Ono sto dobijam u trenutku kada program treba da poredi elemente (novoformirane) liste sa nekom promenjivom je "program terminated with signal 11". Ok, recimo da razumem znacenje ove poruke, da li neko vidi gresku u kodu? Dodao sam neke test metode i asserte u kodu pre ovog poredjenja na osnovu kojih vidim da su mi oba operanda razlicita od nule. Takodje, kompajliranje prolazi bez greske, sto znaci da su tipovi koji se porede isti.
Hvala!
Code:
template<class A>
int
DecisionTable<A>::add_route(InternalMessage<A> &rtmsg,
BGPRouteTable<A> *caller) {
//find the alternative routes, and the old winner if there was one.
list<RouteData<A>* > old_winner; //promenjeno u listu pokazivaca na dati tip. Pre ovoga je bila jedna promenjiva tog tipa
list<RouteData<A> > alternatives;
old_winner = find_alternative_routes_new(caller, rtmsg.net(), alternatives); //ova metoda je definisana ispod i vraca listu pokazivaca tipa RouteData
RouteData<A> *new_winner = NULL;
RouteData<A> new_route(rtmsg.route(), rtmsg.attributes(), caller, //inicijalizacija new_route
rtmsg.origin_peer(), rtmsg.genid());
if (!alternatives.empty()) { //lista alternatives se formira metodom find_alternative_routes_new (ispod)
//add the new route to the pool of possible winners.
alternatives.push_back(new_route);
new_winner = find_winner(alternatives); //metoda find_winner vraca pobednika iz liste alternativa
} else {
//the new route wins by default
new_winner = &new_route;
}
if (!old_winner.empty()) {
typename list<RouteData<A>* >::iterator it;
typename list<RouteData<A>* >::iterator j;
for (it = old_winner.begin(); it != old_winner.end(); it++) //prolaz kroz listu alternativa
if ((*it)->route() == new_winner->route()) { //program ovde puca (signal 11) iako su oba operanda razlicita od nule (testirano!)
//the winner didn't change.
XLOG_ASSERT(!old_winner.empty());
for (j = old_winner.begin(); j != old_winner.end(); j++)
delete *j;
return ADD_UNUSED;
}
}
//neki irelevantan kod u nastavku
template<class A>
list<RouteData<A>* >
DecisionTable<A>::find_alternative_routes_new(
const BGPRouteTable<A> *caller,
const IPNet<A>& net,
list <RouteData<A> >& alternatives) const
{
list<RouteData<A>* > previous_winner; //promenjeno u listu pokazivaca na dati tip. Pre ovoga je bila jedna promenjiva tog tipa
typename map<BGPRouteTable<A>*, PeerTableInfo<A>* >::const_iterator i;
const SubnetRoute<A>* found_route;
for (i = _parents.begin(); i != _parents.end(); i++) {
//We don't need to lookup the route in the parent that the new
//route came from - if this route replaced an earlier route
//from the same parent we'd see it as a replace, not an add
if (i->first != caller) {
uint32_t found_genid;
FPAListRef found_attributes;
found_route = i->first->lookup_route(net, found_genid, //metoda definisana ispod
found_attributes);
if (found_route != NULL) {
PeerTableInfo<A> *pti = i->second;
alternatives.push_back(RouteData<A>(found_route, //popunjava listu alternativa
found_attributes,
pti->route_table(),
pti->peer_handler(),
found_genid));
if (found_route->is_winner()) {
previous_winner.push_back(&(alternatives.back())); //popunjava listu prethodnih pobednika
}
}
}
}
return previous_winner; //..i vraca listu prethodnih pobednika
}
template<class A>
const SubnetRoute<A>*
DecisionTable<A>::lookup_route(const IPNet<A> &net,
uint32_t& genid,
FPAListRef& pa_list) const
{
list <RouteData<A> > alternatives;
RouteData<A>* winner = find_alternative_routes(NULL, net, alternatives);
if (winner == NULL) {
return NULL;
}
else {
genid = winner->genid();
pa_list = winner->attributes();
return winner->route();
}
XLOG_UNREACHABLE();
return NULL;
}
template<class A>
int
DecisionTable<A>::add_route(InternalMessage<A> &rtmsg,
BGPRouteTable<A> *caller) {
//find the alternative routes, and the old winner if there was one.
list<RouteData<A>* > old_winner; //promenjeno u listu pokazivaca na dati tip. Pre ovoga je bila jedna promenjiva tog tipa
list<RouteData<A> > alternatives;
old_winner = find_alternative_routes_new(caller, rtmsg.net(), alternatives); //ova metoda je definisana ispod i vraca listu pokazivaca tipa RouteData
RouteData<A> *new_winner = NULL;
RouteData<A> new_route(rtmsg.route(), rtmsg.attributes(), caller, //inicijalizacija new_route
rtmsg.origin_peer(), rtmsg.genid());
if (!alternatives.empty()) { //lista alternatives se formira metodom find_alternative_routes_new (ispod)
//add the new route to the pool of possible winners.
alternatives.push_back(new_route);
new_winner = find_winner(alternatives); //metoda find_winner vraca pobednika iz liste alternativa
} else {
//the new route wins by default
new_winner = &new_route;
}
if (!old_winner.empty()) {
typename list<RouteData<A>* >::iterator it;
typename list<RouteData<A>* >::iterator j;
for (it = old_winner.begin(); it != old_winner.end(); it++) //prolaz kroz listu alternativa
if ((*it)->route() == new_winner->route()) { //program ovde puca (signal 11) iako su oba operanda razlicita od nule (testirano!)
//the winner didn't change.
XLOG_ASSERT(!old_winner.empty());
for (j = old_winner.begin(); j != old_winner.end(); j++)
delete *j;
return ADD_UNUSED;
}
}
//neki irelevantan kod u nastavku
template<class A>
list<RouteData<A>* >
DecisionTable<A>::find_alternative_routes_new(
const BGPRouteTable<A> *caller,
const IPNet<A>& net,
list <RouteData<A> >& alternatives) const
{
list<RouteData<A>* > previous_winner; //promenjeno u listu pokazivaca na dati tip. Pre ovoga je bila jedna promenjiva tog tipa
typename map<BGPRouteTable<A>*, PeerTableInfo<A>* >::const_iterator i;
const SubnetRoute<A>* found_route;
for (i = _parents.begin(); i != _parents.end(); i++) {
//We don't need to lookup the route in the parent that the new
//route came from - if this route replaced an earlier route
//from the same parent we'd see it as a replace, not an add
if (i->first != caller) {
uint32_t found_genid;
FPAListRef found_attributes;
found_route = i->first->lookup_route(net, found_genid, //metoda definisana ispod
found_attributes);
if (found_route != NULL) {
PeerTableInfo<A> *pti = i->second;
alternatives.push_back(RouteData<A>(found_route, //popunjava listu alternativa
found_attributes,
pti->route_table(),
pti->peer_handler(),
found_genid));
if (found_route->is_winner()) {
previous_winner.push_back(&(alternatives.back())); //popunjava listu prethodnih pobednika
}
}
}
}
return previous_winner; //..i vraca listu prethodnih pobednika
}
template<class A>
const SubnetRoute<A>*
DecisionTable<A>::lookup_route(const IPNet<A> &net,
uint32_t& genid,
FPAListRef& pa_list) const
{
list <RouteData<A> > alternatives;
RouteData<A>* winner = find_alternative_routes(NULL, net, alternatives);
if (winner == NULL) {
return NULL;
}
else {
genid = winner->genid();
pa_list = winner->attributes();
return winner->route();
}
XLOG_UNREACHABLE();
return NULL;
}
Hvala!