Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ITERATOR LIST CORRUPTED in std::string constructor

The code below compiled in Debug configuration in VS2005 SP1 shows two messages with “ITERATOR LIST CORRUPTED” notice.

Code Snippet

#define _SECURE_SCL 0
#define _HAS_ITERATOR_DEBUGGING 0

#include <sstream>
#include <string>

int main()
{
  std::stringstream stream;
  stream << "123" << std::endl;
  std::string str = stream.str();
  std::string::const_iterator itFirst = str.begin();
  int position = str.find('2');
  std::string::const_iterator itSecond = itFirst + position;
  std::string tempStr(itFirst,itSecond); ///< errors are here
  return 0;
}

Is it a bug in the compiler or standard library?

like image 655
Konstantin Tenzin Avatar asked Mar 10 '10 10:03

Konstantin Tenzin


2 Answers

My bad! Edit: Yeah problem with compiler. See this -- particularly the Community Content section.

like image 61
dirkgently Avatar answered Oct 25 '22 14:10

dirkgently


What @dirkgently said in his edit.

Apparently, some code for std::string is located in the runtime dll, in particular the macro definition does not take effect for the constructor an the code for iterator debugging gets executed. You can fix this by linking the runtime library statically.

I would consider this a bug, though perhaps not in the Visual Studio itself, but in the documentation.

like image 25
avakar Avatar answered Oct 25 '22 15:10

avakar