Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8726623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:17:14+00:00 2026-06-13T08:17:14+00:00

I got this strange issue following is the code snippet which is working properly.

  • 0

I got this strange issue following is the code snippet which is working properly.

std::multimap<long,int>::iterator dateItr = reconnQueueDates.begin();

while( dateItr!=reconnQueueDates.end()  ){
LOG_DEBUG("RUN comparision " <<cDateTime<< ", "<<dateItr->first);
if(dateItr->first <= cDateTime){
    long nextTimeout = -1;
   if( (nextTimeout = callReconnects(dateItr->second,dateItr->first))>-1){

        if(nextTimeout>0){
       reconnQueueDates.insert(std::pair<long , int>(nextTimeout, dateItr->second));
            }
            reconnQueueDates.erase(dateItr);
     LOG_DEBUG("modified the iterator ressetting");
     dateItr = reconnQueueDates.begin();
     LOG_DEBUG("resset iter");
   }//end of callreconnect if
}else{
 ++dateItr;
} //else for datetime check
 }//end of while

Before this I was using a for loop with ++dateItr in the loop as follows

 for( ;dateItr!=reconnQueueDates.end();++dateItr  ){
LOG_DEBUG("RUN comparision " <<cDateTime<< ", "<<dateItr->first);
if(dateItr->first <= cDateTime){
   long nextTimeout = -1;
   if( (nextTimeout = callReconnects(dateItr->second,dateItr->first))>-1){


            if(nextTimeout>0){
       reconnQueueDates.insert(std::pair<long , int>(nextTimeout, dateItr->second));       
             }
             reconnQueueDates.erase(dateItr);

        LOG_DEBUG("modified the iterator ressetting");
    dateItr = reconnQueueDates.begin();
    LOG_DEBUG("resset iter");
   }// callReconnect 
} // check datetime

 }// for loop

While debugging I found out that after changing the map inside the loop the iterator value inside the for construct was still using the old address.

I am using and ubuntu 12.04 with g++ version 4.6.3. Seems to me some kind of compiler bug or some kind of optimization doing this.

Any idea which flag or a bug it might be.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:17:14+00:00Added an answer on June 13, 2026 at 8:17 am

    After reconnQueueDates.erase(dateItr); the iterator in dateItr is invalid and any use of it is undefined behaviour. Since both your old and your new for loop use it afterwards, the fact that your new version “works” is purely accidental.

    The correct way to do it is to first extract all data you might still need (including the position of the next iterator) before erasing that element. For example:

    std::multimap<long,int>::iterator dateItr = reconnQueueDates.begin();
    
    while( dateItr!=reconnQueueDates.end()  )
    {
      LOG_DEBUG("RUN comparision " <<cDateTime<< ", "<<dateItr->first);
      if(dateItr->first <= cDateTime)
      {
        std::multimap<long,int>::iterator nextItr = dateItr;
        ++nextItr;
        long nextTimeout = -1;
        if( (nextTimeout = callReconnects(dateItr->second,dateItr->first))>-1)
        {
          std::pair<long , int> newentry = std::make_pair(nextTimeout, dateItr->second);
          reconnQueueDates.erase(dateItr);
          if(nextTimeout>0)
          {
            reconnQueueDates.insert(newentry);
          }
          LOG_DEBUG("modified the iterator resetting");
          nextItr = reconnQueueDates.begin();
          LOG_DEBUG("reset iter");
        }//end of callreconnect if
        dateItr = nextItr;
      }
      else
      {
        ++dateItr;
      } //else for datetime check
    }//end of while
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this strange issue while working with iPhone SDK 3.1.2. My UITableViewCell contains
I've got a strange issue. This is suddenly started happening in the code that
I've got an issue with the following code, it's creating some strange animations, one
I've got this strange situation going on. Imagejpeg is only working when I define
Got this line of code here but its not working. private void Button_Click(object sender,
I've got a strange issue with a google map, which I can only duplicate
i got an strange issue with outOfMemory errors. i had written a application, which
Ok so this is kind of a strange issue, but I have got two
I’ve got this strange problem whereby the content within a scroll viewer increases in
Got this code for a viewscroller from the apple developers site. @synthesize scrollView1, scrollView2;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.