search_n fails with a Debug Assertion - by PeerSch1

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 539946 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 3/7/2010 5:04:43 PM
Access Restriction Public


search_n fails with a Debug Assertion in 'c:\program files (x86)\microsoft visual studio 9.0\vc\include\vector' Line: 163

with the following message:

Expression: ("_Myptr + _Off <= ((_Myvec
*)(this->_Getmycont()))->_Mylast && _Myptr + _Off >= ((_Myvec
*)(this->_Getmycont()))->_Myfirst", 0)

while executing the following code:

std::vector<int> data;
  std::search_n(data.begin(), data.end(), 4, 8, std::equal_to<int>());
Sign in to post a comment.
Posted by Microsoft on 6/22/2010 at 2:25 PM

Thanks again for reporting this bug. We've fixed it, and the fix will be available in VC11.

As always, if you have any further questions, feel free to E-mail me at .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by Microsoft on 3/9/2010 at 7:46 PM

Thanks for reporting this bug. We thought that we had fixed it in VC9 SP1, but we mistakenly fixed only the default version of search_n(), missing the predicate version. Although it's too late to fix this in VC10 RTM, we're keeping this bug active so that it can be fixed in a future release.

Note that your test case won't trigger a spurious debug assertion with VC10. That's because, in debug mode, VC10's algorithms (which we assume are correctly written and don't do bad things with iterators) unwrap their given iterators to unchecked versions for greater speed when debugging with no loss of actual checking. Unfortunately, predicate search_n() is incorrectly written and does something slightly bad with iterators (it increments one out-of-bounds before determining that it's done - it doesn't actually dereference an out-of-bounds iterator, but the bogus increment is forbidden by the Standard). Therefore, the iterator unwrapping conceals the underlying bug.

It's still possible to trigger the underlying bug with more unusual code (I have a test case involving reverse iterators).

If you have any further questions, feel free to E-mail me at .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by Microsoft on 3/8/2010 at 6:42 PM
Thank you for reporting the issue.
We were able to reproduce the issue with the detail steps you provided.We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.