Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Sun C++ std::sort coredump during sorting array of long values

807575Dec 10 2008 — edited Dec 11 2008
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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 8 2009
Added on Dec 10 2008
4 comments
419 views