Click here to Skip to main content
15,920,217 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: ATL : Setting Font Pin
ThatsAlok2-Feb-05 6:41
ThatsAlok2-Feb-05 6:41 
GeneralRe: ATL : Setting Font Pin
Jörgen Sigvardsson7-Feb-05 9:00
Jörgen Sigvardsson7-Feb-05 9:00 
GeneralRe: ATL : Setting Font Pin
ThatsAlok7-Feb-05 15:51
ThatsAlok7-Feb-05 15:51 
GeneralATL COM Pin
surend2k1-Feb-05 19:20
surend2k1-Feb-05 19:20 
GeneralRe: ATL COM Pin
conman1101-Feb-05 20:27
conman1101-Feb-05 20:27 
GeneralRe: ATL COM Pin
vishalmore7-Feb-05 20:30
vishalmore7-Feb-05 20:30 
GeneralRe: ATL COM Pin
vishalmore8-Feb-05 2:58
vishalmore8-Feb-05 2:58 
GeneralSTL Vector sort, memory corruption Pin
Ron Arnan1-Feb-05 10:50
Ron Arnan1-Feb-05 10:50 
Hi,
I have a small console application using C structure, vector and std::sort().
The application crashes in the sort() function with memory corruption. Purify reports many ABW (Array Bound Write) and other illegal usage done by the sort function. Is there a known bug in the sort of stl vectors? Any help is appreciated.

Thanks,
Ron.

(Code sample)

// xx.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "xx.h"

#include <vector>
#include <algorithm>
#include <functional>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

CWinApp theApp;

using namespace std;
#define LENGTH 1000

struct TTT
{
int d;
int h;
int n;
};

class ItemCompare : std::binary_function<TTT&, TTT&, bool>
{
public:
bool operator()(const TTT& t1, TTT& t2)
{
if (t1.d > t2.d)
return true;
else if (t1.h > t2.h)
return true;
else if (t1.n > t2.n)
return true;
else
return false;
}
};


TTT makeTTT(int i)
{
TTT t;
t.d = 1 + (i % 29);
t.h = 1 + (i % 22);
t.n = 1 + (i % 59);

return t;
}

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
vector<TTT> t1;
t1.reserve(LENGTH);
for (int i=0;i<LENGTH;i++)
{
t1.push_back(makeTTT(i));
}
sort(t1.begin(), t1.end(), ItemCompare());
}

return nRetCode;
}



Ron.
GeneralRe: STL Vector sort, memory corruption Pin
Joaquín M López Muñoz2-Feb-05 2:28
Joaquín M López Muñoz2-Feb-05 2:28 
GeneralRe: STL Vector sort, memory corruption Pin
Ron Arnan2-Feb-05 3:55
Ron Arnan2-Feb-05 3:55 
GeneralRe: STL Vector sort, memory corruption Pin
Jörgen Sigvardsson2-Feb-05 10:57
Jörgen Sigvardsson2-Feb-05 10:57 
GeneralRe: STL Vector sort, memory corruption Pin
Joaquín M López Muñoz2-Feb-05 21:59
Joaquín M López Muñoz2-Feb-05 21:59 
GeneralWTL work around WM_NOTIFY Pin
conman1101-Feb-05 7:03
conman1101-Feb-05 7:03 
GeneralEnvDTE::Document.Open returns null Pin
JabraJabra1-Feb-05 6:12
JabraJabra1-Feb-05 6:12 
Generalget project full name Pin
JabraJabra1-Feb-05 2:49
JabraJabra1-Feb-05 2:49 
GeneralTBN_DROPDOWN : Problems with dropdown button in ATL Pin
tnguyen44431-Jan-05 10:16
tnguyen44431-Jan-05 10:16 
GeneralRe: TBN_DROPDOWN : Problems with dropdown button in ATL Pin
Michael Dunn31-Jan-05 11:14
sitebuilderMichael Dunn31-Jan-05 11:14 
GeneralCstring with ATL Pin
JabraJabra31-Jan-05 4:24
JabraJabra31-Jan-05 4:24 
GeneralRe: Cstring with ATL Pin
Ralph Wetzel31-Jan-05 5:49
Ralph Wetzel31-Jan-05 5:49 
GeneralRe: Cstring with ATL Pin
ThatsAlok31-Jan-05 18:09
ThatsAlok31-Jan-05 18:09 
GeneralRe: Cstring with ATL Pin
conman1101-Feb-05 2:12
conman1101-Feb-05 2:12 
GeneralRe: Cstring with ATL Pin
ThatsAlok1-Feb-05 2:54
ThatsAlok1-Feb-05 2:54 
GeneralRe: Cstring with ATL Pin
JabraJabra31-Jan-05 20:36
JabraJabra31-Jan-05 20:36 
Generalfindresource return null Pin
JabraJabra30-Jan-05 0:57
JabraJabra30-Jan-05 0:57 
GeneralParameter problem Pin
Monty229-Jan-05 22:14
Monty229-Jan-05 22:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.