-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
bugSomething isn't workingSomething isn't workingfixedSomething works now, yay!Something works now, yay!
Description
Describe the bug
Commit c40a251 (fixing issue #4091, merged into master in issue #4072) introduced an endless loop into deque::shrink_to_fit(). In specific constellations in regards to _First_used_block_idx, _First_unused_block_idx and _Mask the first loop for deallocating unused blocks runs infinetely.
Command-line test case
#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <math.h>
#include <deque>
int main()
{
std::deque<int> qu;
long it = 0;
while (1)
{
size_t numAlloc = rand() + 1;
for (size_t i = 0; i < numAlloc; i++)
{
qu.push_back(0);
}
size_t numDealloc = rand() + 1;
if (it % 100 == 0 || numDealloc > qu.size())
{
numDealloc = qu.size();
}
for (size_t i = 0; i < numDealloc; i++)
{
qu.pop_front();
}
qu.shrink_to_fit();
printf("iteration %d: %lld\n", ++it, qu.size());
}
return 0;
}
After about 40 iterations deque::shrink_to_fit get's stuck.
Expected behavior
Termination condition for loop is correct so deque::shrink_to_fit() terminates.
STL version
- Visual Studio version
Microsoft Visual Studio Enterprise 2022 Version 17.10 - Visual Studio version
Microsoft Visual Studio Enterprise 2022 Version 17.11.1
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingfixedSomething works now, yay!Something works now, yay!