Microsoft KB Archive/240014

= FIX: Listing Sort Function Removes Elements =

Article ID: 240014

Article Last Modified on 12/8/2003

-

APPLIES TO

 The Standard C++ Library, when used with:  Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Professional Edition

 Microsoft Visual C++ 6.0 Standard Edition 

-

<div class="notice_section">

This article was previously published under Q240014

<div class="symptoms_section">

SYMPTOMS
If a list has over 32K elements, list::sort removes the elements.

Please refer to the Sample Program in the MORE INFORMATION section for details.

<div class="resolution_section">

RESOLUTION
The bug is in the header file.

In the sort function:

if (_I == _MAXN) //_A[_I].merge(_X); /* remove this line and add the line below*/ _A[_I - 1].merge(_X);

In the sort(_Pr3 _Pr) function :

if (_I == _MAXN) //_A[_I].merge(_X, _Pr); /* remove this line and add the line below*/ _A[_I - 1].merge(_X, _Pr);<BR/> If you are sorting through a list larger than 32K, increasing _MAXN from 15 to 25 would improve the performance.

NOTE: Since the resolution involves modifying a system header file, extreme care should be taken to make sure nothing else is changed in the header file. Microsoft is not responsible for any problems resulting due to unwanted changes to the system header files.

<div class="status_section">

STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

This problem was corrected in Microsoft Visual C++ .NET.

<div class="moreinformation_section">

Steps to Reproduce Behavior
The following sample program demonstrates the bug. //test.cpp //Compiler options : /GX #include #include #include

void main {    std::list mylist;

int i;    int last = 32768;

for (i = 0; i < last; i++) mylist.push_back(i);

std::cout << "Size before sort: " << mylist.size << "\n"; mylist.sort; std::cout << "Size after sort: " << mylist.size << "\n"; }

Actual Results: Size before sort: 32768 Size after sort: 0

Expected Results: Size before sort: 32768 Size after sort: 32768

Additional query words: STL

Keywords: kbbug kbfix kbnoupdate kblangcpp kbstl KB240014

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.