Hello,
I got core dump during execution following test program on both Solaris 9 (compile by CC: Sun C++ 5.5 Patch 113817-19 2006/10/13) and Solaris 10 platforms (compile by CC: Sun C++ 5.9 SunOS_sparc Patch 124863-01 2007/07/25).
Core is dumped during sorting array of about 120k elements of unsigned long types using STL std:sort. The input data is available at link: [file.txt|http://www.savefile.com/files/1924004]
When I change sorting methods to std::stable_sort program works fine.
The funny thing is that when I change order of last two values of input data (swap), sorting is successful with std::sort.
Can anyone tell me if it is Sun C++ compiler bug ?Can I use std::stable_sort method safely?
Below code:
#include <iostream.h>
#include <fstream.h>
#include <set>
#include <string>
int main( int argc, char** argv )
{
char readStr[256];
ifstream file;
unsigned long *l;
int i=0;
l = new unsigned long[119016];
if (l ==0)
{
cout << "Error in allocate memory";
return -1;
}
file.open("file.txt");
if (!file)
{
cout << "Error in openening file";
return -1;
}
while(file.getline(readStr, 256,'\n'))
{
cout << readStr<<endl;
l= atol(readStr);
cout << l[i]<<endl;
i++;
}
std::sort(l,l+119016); //core dump here!!!
for (i=0;i<119016;i++)
{
cout <<l[i]<<endl;
}
file.close();
delete [] l;
return( 0 );
}
Greetings
Robert