suppressed memory fault (call to ++it on a invalid iterator). Simplified a bit some syntax

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3623 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-10-06 19:32:55 +00:00
parent 709f9b515b
commit a76566c65d

View File

@ -326,11 +326,12 @@ int bdQuery::addPeer(const bdId *id, uint32_t mode)
fprintf(stderr, "Dropping Peer that dont reply\n"); fprintf(stderr, "Dropping Peer that dont reply\n");
#endif #endif
bool removed = false; bool removed = false;
for(it = mClosest.begin(); (!removed) && (it != mClosest.end()); it++) for(it = mClosest.begin(); it != mClosest.end(); ++it)
{ {
time_t sendts = ts - it->second.mLastSendTime; time_t sendts = ts - it->second.mLastSendTime;
bool hasSent = (it->second.mLastSendTime != 0); bool hasSent = (it->second.mLastSendTime != 0);
bool hasReply = (it->second.mLastRecvTime >= it->second.mLastSendTime); bool hasReply = (it->second.mLastRecvTime >= it->second.mLastSendTime);
if ((hasSent) && (!hasReply) && (sendts > EXPECTED_REPLY)) if ((hasSent) && (!hasReply) && (sendts > EXPECTED_REPLY))
{ {
#ifdef DEBUG_QUERY #ifdef DEBUG_QUERY
@ -340,6 +341,7 @@ int bdQuery::addPeer(const bdId *id, uint32_t mode)
#endif #endif
mClosest.erase(it); mClosest.erase(it);
removed = true; removed = true;
break ;
} }
} }
} }
@ -349,13 +351,13 @@ int bdQuery::addPeer(const bdId *id, uint32_t mode)
{ {
std::multimap<bdMetric, bdPeer>::iterator it; std::multimap<bdMetric, bdPeer>::iterator it;
it = mClosest.end(); it = mClosest.end();
if (mClosest.begin() != mClosest.end()) if (!mClosest.empty())
{ {
it--; it--;
#ifdef DEBUG_QUERY #ifdef DEBUG_QUERY
fprintf(stderr, "Removing Furthest Peer: "); fprintf(stderr, "Removing Furthest Peer: ");
mFns->bdPrintId(std::cerr, &(it->second.mPeerId)); mFns->bdPrintId(std::cerr, &(it->second.mPeerId));
fprintf(stderr, "\n"); fprintf(stderr, "\n");
#endif #endif
mClosest.erase(it); mClosest.erase(it);
@ -503,15 +505,15 @@ int bdQuery::addPotentialPeer(const bdId *id, uint32_t mode)
{ {
std::multimap<bdMetric, bdPeer>::iterator it; std::multimap<bdMetric, bdPeer>::iterator it;
it = mPotentialClosest.end(); it = mPotentialClosest.end();
if (mPotentialClosest.begin() != mPotentialClosest.end())
{
it--;
#ifdef DEBUG_QUERY
fprintf(stderr, "Removing Furthest Peer: ");
mFns->bdPrintId(std::cerr, &(it->second.mPeerId));
fprintf(stderr, "\n");
#endif
if(!mPotentialClosest.empty())
{
--it;
#ifdef DEBUG_QUERY
fprintf(stderr, "Removing Furthest Peer: ");
mFns->bdPrintId(std::cerr, &(it->second.mPeerId));
fprintf(stderr, "\n");
#endif
mPotentialClosest.erase(it); mPotentialClosest.erase(it);
} }
} }