Home Dashboard Directory Help
Search

search_n fails with a Debug Assertion by PeerSch1


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 539946
Opened: 3/7/2010 5:04:43 PM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

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;
data.push_back(0);
data.push_back(7);
data.push_back(2);
data.push_back(5);
data.push_back(7);
std::search_n(data.begin(), data.end(), 4, 8, std::equal_to<int>());
Details
Sign in to post a comment.
Posted by Microsoft on 6/22/2010 at 2:25 PM
Hi,

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 stl@microsoft.com .

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

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 stl@microsoft.com .

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.
Sign in to post a workaround.