Windows XP error when running a C++ executable

S

Sandy

HI All,
I have created a MFC exe using VC++ .NET 2003 on Windows XP Prof
service pack 2 and it works properly on my machine, but when I run the
same exe on a different machine (Windows XP Prof SP-2), The application

is bought up and after some time its throwing a windows xp error dialog

box saying,

I am also running the same application on 2 more machines there
everything works fine.

Here is thr Windows XP error dialog box that appreas when its crashed
TODO: <File description> has encountered a problem and needs to close.
We are sorry for any inconenience.

If you are in the middle of something, the information you were working

on might be lost.


Please tell Microsoft about this problem.


blab blah....


I have function called OnNotifyNewData (WPARAM wParam, LPARAM lParam)
which appreas to be cauing the problem. When I run the application
commenting this function its didnt crashed.

LRESULT CUserViewFrame::OnNotifyNewData (WPARAM wParam, LPARAM lParam)
{
const char* strVariable("CUserViewFrame::OnNotifyNewData START");
const char* strValue("6");
CUtility::LogDebugInfo( strVariable, strValue);

WRITE_LOG_FUNCTION_ENTRY("LRESULT CUserViewFrame::OnNotifyNewData
(WPARAM wParam, LPARAM lParam)")

PInstData pInstData = (PInstData)wParam;
if (!pInstData) return 0;

CString csText;
char buffer[255];
LVFINDINFO info;
int iIndex = 0;

PSystemSetting pSystemSetting = CSystemSetting::GetObject();

info.flags = LVFI_WRAP|LVFI_STRING;
std::vector<CMarketData>::const_iterator iter;
std::vector<CParticipant>::const_iterator iterpart;

const std::vector<CMarketData> & userListBid =
pInstData->GetMarketDataBid();
for (iter = userListBid.begin(); iter != userListBid.end(); iter++)
{
const std::vector<CParticipant> & participants =
iter->GetParticipants();
for (iterpart = participants.begin(); iterpart != participants.end();
iterpart++)
{
if (iterpart->GetSize() > 0.0 && iter->GetPrice() > 0.0)
{
memset(&buffer, 0, sizeof(buffer));
if (sizeof(iterpart->GetUserName()/*.c_str()*/) > 255
continue;
//sprintf(buffer, "%s", iterpart->GetUserName()/*.c_str()*/);
info.psz = iterpart->GetUserName();
iIndex = m_ctrlUserListCtrl.FindItem(&info);
if (iIndex == -1)
{ // insert the item
iIndex = m_ctrlUserListCtrl.GetItemCount();

if (sizeof(iterpart->GetUserName()/*.c_str()*/) > 255
continue;
//csText.Format(TEXT("%s"), iterpart->GetUserName()/*.c_str()
csText = iterpart->GetUserName(); //Sanjeev 012407
int size = iterpart->GetUserName().GetLength();
char bufsize[20];
memset(&bufsize, 0, sizeof(bufsize));
_itoa(size,bufsize,10);
CUtility::LogDebugInfo( "OnNotifyNewData - BID UserName", bufsize);
m_ctrlUserListCtrl.InsertItem(LVIF_TEXT|LVIF_STATE, iIndex, csText,
0, LVIS_SELECTED, 0, 0);
char * pchText = new char [csText.GetLength() + 1];
strcpy(pchText, (LPCTSTR)csText);
m_ctrlUserListCtrl.SetItemData(iIndex, (DWORD)pchText);
}
if (sizeof(pInstData->GetInstName()/*.c_str()*/) > 255)
continue;
//csText.Format(TEXT("%s"),
pInstData->GetInstName()/*.c_str()*/); csText =
pInstData->GetInstName();
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::BID_INST, csText);

memset(&buffer, 0, sizeof(buffer));
sprintf(buffer, "%%.%df", pSystemSetting->GetDecimalSize());
csText.Format(buffer, iterpart->GetSize());
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::BID_SIZE, csText);

memset(&buffer, 0, sizeof(buffer));
sprintf(buffer, "%%.%df", pSystemSetting->GetDecimalPrice());
csText.Format(buffer, iter->GetPrice());
m_ctrlUserListCtrl.SetItemText(iIndex,

eUserViewListColumn::BID_PRICE, csText);

if (sizeof(iterpart->GetTimestamp().c_str()) > 255)
continue;
csText.Format("%s", iterpart->GetTimestamp().c_str());
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::BID_TIME, csText);
}
}
}

const std::vector<CMarketData> & userListAsk =
pInstData->GetMarketDataAsk();
for (iter = userListAsk.begin(); iter != userListAsk.end(); iter++)
{
const std::vector<CParticipant> & participants =
iter->GetParticipants();
for (iterpart = participants.begin(); iterpart != participants.end();
iterpart++)
{
if (iterpart->GetSize() > 0.0 && iter->GetPrice() > 0.0)
{
memset(&buffer, 0, sizeof(buffer));
if (sizeof(iterpart->GetUserName()/*.c_str()*/) > 255)
continue;
//sprintf(buffer, "%s", iterpart->GetUserName()/*.c_str()*/);
int size = iterpart->GetUserName().GetLength();
char bufsize[20];
memset(&bufsize, 0, sizeof(bufsize));
_itoa(size,bufsize,10);
CUtility::LogDebugInfo( "OnNotifyNewData - ASK UserName", bufsize);
info.psz = iterpart->GetUserName();
iIndex = m_ctrlUserListCtrl.FindItem(&info);
if (iIndex == -1)
{ // insert the item
iIndex = m_ctrlUserListCtrl.GetItemCount();
if (sizeof(iterpart->GetUserName()/*.c_str()*/) > 255)
continue;
//csText.Format(TEXT("%s"), iterpart->GetUserName()/*.c_str()*/);
csText = iterpart->GetUserName();
m_ctrlUserListCtrl.InsertItem(LVIF_TEXT|LVIF_STATE, iIndex, csText,
0, LVIS_SELECTED, 0, 0);
char * pchText = new char [csText.GetLength() + 1];
strcpy(pchText, (LPCTSTR)csText);
m_ctrlUserListCtrl.SetItemData(iIndex, (DWORD)pchText);
}
if (sizeof(pInstData->GetInstName()/*.c_str()*/) > 255)
continue;
//csText.Format(TEXT("%s"), pInstData->GetInstName().c_str());
csText = pInstData->GetInstName();
m_ctrlUserListCtrl.SetItemText(iIndex,

eUserViewListColumn::ASK_INST, csText);

memset(&buffer, 0, sizeof(buffer));
sprintf(buffer, "%%.%df", pSystemSetting->GetDecimalSize());
csText.Format(buffer, iterpart->GetSize());
m_ctrlUserListCtrl.SetItemText(iIndex,

eUserViewListColumn::ASK_SIZE, csText);

memset(&buffer, 0, sizeof(buffer));
sprintf(buffer, "%%.%df", pSystemSetting->GetDecimalPrice());
csText.Format(buffer, iter->GetPrice());
m_ctrlUserListCtrl.SetItemText(iIndex,

eUserViewListColumn::ASK_PRICE, csText);

if (sizeof(iterpart->GetTimestamp().c_str()) > 255)
continue;
csText.Format("%s", iterpart->GetTimestamp().c_str());
m_ctrlUserListCtrl.SetItemText(iIndex,

eUserViewListColumn::ASK_TIME, csText);
}
}
}

VERIFY(m_ctrlUserListCtrl.SortItems( CompareFunction, r

einterpret_cast<DWORD>(&m_ctrlUserListCtrl)));

WRITE_LOG_FUNCTION_EXIT("LRESULT
CUserViewFrame::OnNotifyNewData (WPARAM wParam,
PARAM
lParam)")

const char* strVariable1("CUserViewFrame::OnNotifyNewData END");
CUtility::LogDebugInfo( strVariable1, strValue);

return 0;
}


Is there any chance the sprintf or CString Format function is creating
this problem.

I have spent lot of time it undertsanding this bug with no success. Any
help would be greatly appreciated.

Regards,
Sandy
 
M

Marcin Domaslawski

Hi,

It's a bit looks like an pointers problem but on first look I don't see any.
Anyway I've noticed that you allocates some memory but don't deallocate it
e.g.
char * pchText = new char [csText.GetLength() + 1];

besides, after:
strcpy(pchText, (LPCTSTR)csText);

what value has got pchText[ csText.GetLength() ] ? - everytime it can be
different because you not clear pchText.


Marcin Domaslawski

Uzytkownik "Sandy said:
HI All,
I have created a MFC exe using VC++ .NET 2003 on Windows XP Prof
service pack 2 and it works properly on my machine, but when I run the
same exe on a different machine (Windows XP Prof SP-2), The application

is bought up and after some time its throwing a windows xp error dialog

box saying,

I am also running the same application on 2 more machines there
everything works fine.

Here is thr Windows XP error dialog box that appreas when its crashed
TODO: <File description> has encountered a problem and needs to close.
We are sorry for any inconenience.

If you are in the middle of something, the information you were working

on might be lost.


Please tell Microsoft about this problem.


blab blah....


I have function called OnNotifyNewData (WPARAM wParam, LPARAM lParam)
which appreas to be cauing the problem. When I run the application
commenting this function its didnt crashed.

LRESULT CUserViewFrame::OnNotifyNewData (WPARAM wParam, LPARAM lParam)
{
const char* strVariable("CUserViewFrame::OnNotifyNewData START");
const char* strValue("6");
CUtility::LogDebugInfo( strVariable, strValue);

WRITE_LOG_FUNCTION_ENTRY("LRESULT CUserViewFrame::OnNotifyNewData
(WPARAM wParam, LPARAM lParam)")

PInstData pInstData = (PInstData)wParam;
if (!pInstData) return 0;

CString csText;
char buffer[255];
LVFINDINFO info;
int iIndex = 0;

PSystemSetting pSystemSetting = CSystemSetting::GetObject();

info.flags = LVFI_WRAP|LVFI_STRING;
std::vector<CMarketData>::const_iterator iter;
std::vector<CParticipant>::const_iterator iterpart;

const std::vector<CMarketData> & userListBid =
pInstData->GetMarketDataBid();
for (iter = userListBid.begin(); iter != userListBid.end(); iter++)
{
const std::vector<CParticipant> & participants =
iter->GetParticipants();
for (iterpart = participants.begin(); iterpart != participants.end();
iterpart++)
{
if (iterpart->GetSize() > 0.0 && iter->GetPrice() > 0.0)
{
memset(&buffer, 0, sizeof(buffer));
if (sizeof(iterpart->GetUserName()/*.c_str()*/) > 255
continue;
//sprintf(buffer, "%s", iterpart->GetUserName()/*.c_str()*/);
info.psz = iterpart->GetUserName();
iIndex = m_ctrlUserListCtrl.FindItem(&info);
if (iIndex == -1)
{ // insert the item
iIndex = m_ctrlUserListCtrl.GetItemCount();

if (sizeof(iterpart->GetUserName()/*.c_str()*/) > 255
continue;
//csText.Format(TEXT("%s"), iterpart->GetUserName()/*.c_str()
csText = iterpart->GetUserName(); //Sanjeev 012407
int size = iterpart->GetUserName().GetLength();
char bufsize[20];
memset(&bufsize, 0, sizeof(bufsize));
_itoa(size,bufsize,10);
CUtility::LogDebugInfo( "OnNotifyNewData - BID UserName", bufsize);
m_ctrlUserListCtrl.InsertItem(LVIF_TEXT|LVIF_STATE, iIndex, csText,
0, LVIS_SELECTED, 0, 0);
char * pchText = new char [csText.GetLength() + 1];
strcpy(pchText, (LPCTSTR)csText);
m_ctrlUserListCtrl.SetItemData(iIndex, (DWORD)pchText);
}
if (sizeof(pInstData->GetInstName()/*.c_str()*/) > 255)
continue;
//csText.Format(TEXT("%s"),
pInstData->GetInstName()/*.c_str()*/); csText =
pInstData->GetInstName();
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::BID_INST, csText);

memset(&buffer, 0, sizeof(buffer));
sprintf(buffer, "%%.%df", pSystemSetting->GetDecimalSize());
csText.Format(buffer, iterpart->GetSize());
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::BID_SIZE, csText);

memset(&buffer, 0, sizeof(buffer));
sprintf(buffer, "%%.%df", pSystemSetting->GetDecimalPrice());
csText.Format(buffer, iter->GetPrice());
m_ctrlUserListCtrl.SetItemText(iIndex,

eUserViewListColumn::BID_PRICE, csText);

if (sizeof(iterpart->GetTimestamp().c_str()) > 255)
continue;
csText.Format("%s", iterpart->GetTimestamp().c_str());
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::BID_TIME, csText);
}
}
}

const std::vector<CMarketData> & userListAsk =
pInstData->GetMarketDataAsk();
for (iter = userListAsk.begin(); iter != userListAsk.end(); iter++)
{
const std::vector<CParticipant> & participants =
iter->GetParticipants();
for (iterpart = participants.begin(); iterpart != participants.end();
iterpart++)
{
if (iterpart->GetSize() > 0.0 && iter->GetPrice() > 0.0)
{
memset(&buffer, 0, sizeof(buffer));
if (sizeof(iterpart->GetUserName()/*.c_str()*/) > 255)
continue;
//sprintf(buffer, "%s", iterpart->GetUserName()/*.c_str()*/);
int size = iterpart->GetUserName().GetLength();
char bufsize[20];
memset(&bufsize, 0, sizeof(bufsize));
_itoa(size,bufsize,10);
CUtility::LogDebugInfo( "OnNotifyNewData - ASK UserName", bufsize);
info.psz = iterpart->GetUserName();
iIndex = m_ctrlUserListCtrl.FindItem(&info);
if (iIndex == -1)
{ // insert the item
iIndex = m_ctrlUserListCtrl.GetItemCount();
if (sizeof(iterpart->GetUserName()/*.c_str()*/) > 255)
continue;
//csText.Format(TEXT("%s"), iterpart->GetUserName()/*.c_str()*/);
csText = iterpart->GetUserName();
m_ctrlUserListCtrl.InsertItem(LVIF_TEXT|LVIF_STATE, iIndex, csText,
0, LVIS_SELECTED, 0, 0);
char * pchText = new char [csText.GetLength() + 1];
strcpy(pchText, (LPCTSTR)csText);
m_ctrlUserListCtrl.SetItemData(iIndex, (DWORD)pchText);
}
if (sizeof(pInstData->GetInstName()/*.c_str()*/) > 255)
continue;
//csText.Format(TEXT("%s"), pInstData->GetInstName().c_str());
csText = pInstData->GetInstName();
m_ctrlUserListCtrl.SetItemText(iIndex,

eUserViewListColumn::ASK_INST, csText);

memset(&buffer, 0, sizeof(buffer));
sprintf(buffer, "%%.%df", pSystemSetting->GetDecimalSize());
csText.Format(buffer, iterpart->GetSize());
m_ctrlUserListCtrl.SetItemText(iIndex,

eUserViewListColumn::ASK_SIZE, csText);

memset(&buffer, 0, sizeof(buffer));
sprintf(buffer, "%%.%df", pSystemSetting->GetDecimalPrice());
csText.Format(buffer, iter->GetPrice());
m_ctrlUserListCtrl.SetItemText(iIndex,

eUserViewListColumn::ASK_PRICE, csText);

if (sizeof(iterpart->GetTimestamp().c_str()) > 255)
continue;
csText.Format("%s", iterpart->GetTimestamp().c_str());
m_ctrlUserListCtrl.SetItemText(iIndex,

eUserViewListColumn::ASK_TIME, csText);
}
}
}

VERIFY(m_ctrlUserListCtrl.SortItems( CompareFunction, r

einterpret_cast<DWORD>(&m_ctrlUserListCtrl)));

WRITE_LOG_FUNCTION_EXIT("LRESULT
CUserViewFrame::OnNotifyNewData (WPARAM wParam,
PARAM
lParam)")

const char* strVariable1("CUserViewFrame::OnNotifyNewData END");
CUtility::LogDebugInfo( strVariable1, strValue);

return 0;
}


Is there any chance the sprintf or CString Format function is creating
this problem.

I have spent lot of time it undertsanding this bug with no success. Any
help would be greatly appreciated.

Regards,
Sandy
 
S

Sandy

Appreciate your response.
I will make note of your suggestion and delete the pointer after its
use. To give some more input, When I look the in the drwatson.exe its
shows some information saying C:\Tools\My.exe MSVCR71.dll memcpy.

I am unable to get what exactly drwatson exe is saying.

And one question, when you suspect it as a pointer problem , why is it
working well on my machine and other 2 machines. I have this crash only
on one machine which has same OS and SP.

Regards,\Sanjeev
Hi,

It's a bit looks like an pointers problem but on first look I don't see any.
Anyway I've noticed that you allocates some memory but don't deallocate it
e.g.
char * pchText = new char [csText.GetLength() + 1];besides, after:
strcpy(pchText, (LPCTSTR)csText);what value has got pchText[ csText.GetLength() ] ? - everytime it can be
different because you not clear pchText.

Marcin Domaslawski

Uzytkownik "Sandy" <[email protected]> napisal w wiadomosci

HI All,
I have created a MFC exe using VC++ .NET 2003 onWindowsXPProf
service pack 2 and it works properly on my machine, but when I run the
same exe on a different machine (WindowsXPProf SP-2), The application
is bought up and after some time its throwing awindowsxperrordialog
box saying,
I am alsorunningthe same application on 2 more machines there
everything works fine.
Here is thrWindowsXPerrordialog box that appreas when its crashed
TODO: <File description> has encountered a problem and needs to close.
We are sorry for any inconenience.
If you are in the middle of something, the information you were working
on might be lost.
Please tell Microsoft about this problem.
blab blah....
I have function called OnNotifyNewData (WPARAM wParam, LPARAM lParam)
which appreas to be cauing the problem. When I run the application
commenting this function its didnt crashed.
LRESULT CUserViewFrame::OnNotifyNewData (WPARAM wParam, LPARAM lParam)
{
const char* strVariable("CUserViewFrame::OnNotifyNewData START");
const char* strValue("6");
CUtility::LogDebugInfo( strVariable, strValue);
WRITE_LOG_FUNCTION_ENTRY("LRESULT CUserViewFrame::OnNotifyNewData
(WPARAM wParam, LPARAM lParam)")
PInstData pInstData = (PInstData)wParam;
if (!pInstData) return 0;
CString csText;
char buffer[255];
LVFINDINFO info;
int iIndex = 0;
PSystemSetting pSystemSetting = CSystemSetting::GetObject();
info.flags = LVFI_WRAP|LVFI_STRING;
std::vector<CMarketData>::const_iterator iter;
std::vector<CParticipant>::const_iterator iterpart;
const std::vector<CMarketData> & userListBid =
pInstData->GetMarketDataBid();
for (iter = userListBid.begin(); iter != userListBid.end(); iter++)
{
const std::vector<CParticipant> & participants =
iter->GetParticipants();
for (iterpart = participants.begin(); iterpart != participants.end();
iterpart++)
{
if (iterpart->GetSize() > 0.0 && iter->GetPrice() > 0.0)
{
memset(&buffer, 0, sizeof(buffer));
if (sizeof(iterpart->GetUserName()/*.c_str()*/) > 255
continue;
//sprintf(buffer, "%s", iterpart->GetUserName()/*.c_str()*/);
info.psz = iterpart->GetUserName();
iIndex = m_ctrlUserListCtrl.FindItem(&info);
if (iIndex == -1)
{ // insert the item
iIndex = m_ctrlUserListCtrl.GetItemCount();
if (sizeof(iterpart->GetUserName()/*.c_str()*/) > 255
continue;
//csText.Format(TEXT("%s"), iterpart->GetUserName()/*.c_str()
csText = iterpart->GetUserName(); //Sanjeev 012407
int size = iterpart->GetUserName().GetLength();
char bufsize[20];
memset(&bufsize, 0, sizeof(bufsize));
_itoa(size,bufsize,10);
CUtility::LogDebugInfo( "OnNotifyNewData - BID UserName", bufsize);
m_ctrlUserListCtrl.InsertItem(LVIF_TEXT|LVIF_STATE, iIndex, csText,
0, LVIS_SELECTED, 0, 0);
char * pchText = new char [csText.GetLength() + 1];
strcpy(pchText, (LPCTSTR)csText);
m_ctrlUserListCtrl.SetItemData(iIndex, (DWORD)pchText);
}
if (sizeof(pInstData->GetInstName()/*.c_str()*/) > 255)
continue;
//csText.Format(TEXT("%s"),
pInstData->GetInstName()/*.c_str()*/); csText =
pInstData->GetInstName();
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::BID_INST, csText);
memset(&buffer, 0, sizeof(buffer));
sprintf(buffer, "%%.%df", pSystemSetting->GetDecimalSize());
csText.Format(buffer, iterpart->GetSize());
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::BID_SIZE, csText);
memset(&buffer, 0, sizeof(buffer));
sprintf(buffer, "%%.%df", pSystemSetting->GetDecimalPrice());
csText.Format(buffer, iter->GetPrice());
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::BID_PRICE, csText);
if (sizeof(iterpart->GetTimestamp().c_str()) > 255)
continue;
csText.Format("%s", iterpart->GetTimestamp().c_str());
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::BID_TIME, csText);
}
}
}
const std::vector<CMarketData> & userListAsk =
pInstData->GetMarketDataAsk();
for (iter = userListAsk.begin(); iter != userListAsk.end(); iter++)
{
const std::vector<CParticipant> & participants =
iter->GetParticipants();
for (iterpart = participants.begin(); iterpart != participants.end();
iterpart++)
{
if (iterpart->GetSize() > 0.0 && iter->GetPrice() > 0.0)
{
memset(&buffer, 0, sizeof(buffer));
if (sizeof(iterpart->GetUserName()/*.c_str()*/) > 255)
continue;
//sprintf(buffer, "%s", iterpart->GetUserName()/*.c_str()*/);
int size = iterpart->GetUserName().GetLength();
char bufsize[20];
memset(&bufsize, 0, sizeof(bufsize));
_itoa(size,bufsize,10);
CUtility::LogDebugInfo( "OnNotifyNewData - ASK UserName", bufsize);
info.psz = iterpart->GetUserName();
iIndex = m_ctrlUserListCtrl.FindItem(&info);
if (iIndex == -1)
{ // insert the item
iIndex = m_ctrlUserListCtrl.GetItemCount();
if (sizeof(iterpart->GetUserName()/*.c_str()*/) > 255)
continue;
//csText.Format(TEXT("%s"), iterpart->GetUserName()/*.c_str()*/);
csText = iterpart->GetUserName();
m_ctrlUserListCtrl.InsertItem(LVIF_TEXT|LVIF_STATE, iIndex, csText,
0, LVIS_SELECTED, 0, 0);
char * pchText = new char [csText.GetLength() + 1];
strcpy(pchText, (LPCTSTR)csText);
m_ctrlUserListCtrl.SetItemData(iIndex, (DWORD)pchText);
}
if (sizeof(pInstData->GetInstName()/*.c_str()*/) > 255)
continue;
//csText.Format(TEXT("%s"), pInstData->GetInstName().c_str());
csText = pInstData->GetInstName();
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::ASK_INST, csText);
memset(&buffer, 0, sizeof(buffer));
sprintf(buffer, "%%.%df", pSystemSetting->GetDecimalSize());
csText.Format(buffer, iterpart->GetSize());
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::ASK_SIZE, csText);
memset(&buffer, 0, sizeof(buffer));
sprintf(buffer, "%%.%df", pSystemSetting->GetDecimalPrice());
csText.Format(buffer, iter->GetPrice());
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::ASK_PRICE, csText);
if (sizeof(iterpart->GetTimestamp().c_str()) > 255)
continue;
csText.Format("%s", iterpart->GetTimestamp().c_str());
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::ASK_TIME, csText);
}
}
}
VERIFY(m_ctrlUserListCtrl.SortItems( CompareFunction, r

WRITE_LOG_FUNCTION_EXIT("LRESULT
CUserViewFrame::OnNotifyNewData (WPARAM wParam,
PARAM
lParam)")
const char* strVariable1("CUserViewFrame::OnNotifyNewData END");
CUtility::LogDebugInfo( strVariable1, strValue);
return 0;
}
Is there any chance the sprintf or CString Format function is creating
this problem.
I have spent lot of time it undertsanding this bug with no success. Any
help would be greatly appreciated.
Regards,
Sandy- Hide quoted text -- Show quoted text -
 
M

Marcin Domaslawski

Hi,

This is it - when you don't initialize your pointers or variable, theirs
value are unpredictible - every time you launch your app, it depends on
trash left by e.g. others apps - simply big big mess. In this case your app
can run on your machine and 20 others but on the 4 another will crash and
this vulnerability usually is dificult to find out.

I prefer allocating memory for non numerical variables (like int or DWORD)
and clearing it e.g. instead LVFINDINFO info; :
LVFINDINFO * info = new LVFINDINFO;
memset( info, 0, sizeof( LVFINDINFO ) );
and when it is not needed any longer delete info;

If you have problems with determine where exactly problem is, try to comment
some part of code in function and test then.

About memcpy - i can't see it in your function but there is strcpy - did you
try to replace it:
memcpy ( pchText, (LPSTR)(LPCTSTR)csText, csText.GetLength() );

Marcin Domaslawski



Uzytkownik "Sandy said:
Appreciate your response.
I will make note of your suggestion and delete the pointer after its
use. To give some more input, When I look the in the drwatson.exe its
shows some information saying C:\Tools\My.exe MSVCR71.dll memcpy.

I am unable to get what exactly drwatson exe is saying.

And one question, when you suspect it as a pointer problem , why is it
working well on my machine and other 2 machines. I have this crash only
on one machine which has same OS and SP.

Regards,\Sanjeev
Hi,

It's a bit looks like an pointers problem but on first look I don't see
any.
Anyway I've noticed that you allocates some memory but don't deallocate
it
e.g.
char * pchText = new char [csText.GetLength() + 1];besides, after:
strcpy(pchText, (LPCTSTR)csText);what value has got pchText[
csText.GetLength() ] ? - everytime it can be
different because you not clear pchText.

Marcin Domaslawski

Uzytkownik "Sandy" <[email protected]> napisal w
wiadomosci

HI All,
I have created a MFC exe using VC++ .NET 2003 onWindowsXPProf
service pack 2 and it works properly on my machine, but when I run the
same exe on a different machine (WindowsXPProf SP-2), The application
is bought up and after some time its throwing awindowsxperrordialog
box saying,
I am alsorunningthe same application on 2 more machines there
everything works fine.
Here is thrWindowsXPerrordialog box that appreas when its crashed
TODO: <File description> has encountered a problem and needs to close.
We are sorry for any inconenience.
If you are in the middle of something, the information you were working
on might be lost.
Please tell Microsoft about this problem.
blab blah....
I have function called OnNotifyNewData (WPARAM wParam, LPARAM lParam)
which appreas to be cauing the problem. When I run the application
commenting this function its didnt crashed.
LRESULT CUserViewFrame::OnNotifyNewData (WPARAM wParam, LPARAM lParam)
{
const char* strVariable("CUserViewFrame::OnNotifyNewData START");
const char* strValue("6");
CUtility::LogDebugInfo( strVariable, strValue);
WRITE_LOG_FUNCTION_ENTRY("LRESULT CUserViewFrame::OnNotifyNewData
(WPARAM wParam, LPARAM lParam)")
PInstData pInstData = (PInstData)wParam;
if (!pInstData) return 0;
CString csText;
char buffer[255];
LVFINDINFO info;
int iIndex = 0;
PSystemSetting pSystemSetting = CSystemSetting::GetObject();
info.flags = LVFI_WRAP|LVFI_STRING;
std::vector<CMarketData>::const_iterator iter;
std::vector<CParticipant>::const_iterator iterpart;
const std::vector<CMarketData> & userListBid =
pInstData->GetMarketDataBid();
for (iter = userListBid.begin(); iter != userListBid.end(); iter++)
{
const std::vector<CParticipant> & participants =
iter->GetParticipants();
for (iterpart = participants.begin(); iterpart != participants.end();
iterpart++)
{
if (iterpart->GetSize() > 0.0 && iter->GetPrice() > 0.0)
{
memset(&buffer, 0, sizeof(buffer));
if (sizeof(iterpart->GetUserName()/*.c_str()*/) > 255
continue;
//sprintf(buffer, "%s", iterpart->GetUserName()/*.c_str()*/);
info.psz = iterpart->GetUserName();
iIndex = m_ctrlUserListCtrl.FindItem(&info);
if (iIndex == -1)
{ // insert the item
iIndex = m_ctrlUserListCtrl.GetItemCount();
if (sizeof(iterpart->GetUserName()/*.c_str()*/) > 255
continue;
//csText.Format(TEXT("%s"), iterpart->GetUserName()/*.c_str()
csText = iterpart->GetUserName(); //Sanjeev 012407
int size = iterpart->GetUserName().GetLength();
char bufsize[20];
memset(&bufsize, 0, sizeof(bufsize));
_itoa(size,bufsize,10);
CUtility::LogDebugInfo( "OnNotifyNewData - BID UserName", bufsize);
m_ctrlUserListCtrl.InsertItem(LVIF_TEXT|LVIF_STATE, iIndex, csText,
0, LVIS_SELECTED, 0, 0);
char * pchText = new char [csText.GetLength() + 1];
strcpy(pchText, (LPCTSTR)csText);
m_ctrlUserListCtrl.SetItemData(iIndex, (DWORD)pchText);
}
if (sizeof(pInstData->GetInstName()/*.c_str()*/) > 255)
continue;
//csText.Format(TEXT("%s"),
pInstData->GetInstName()/*.c_str()*/); csText =
pInstData->GetInstName();
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::BID_INST, csText);
memset(&buffer, 0, sizeof(buffer));
sprintf(buffer, "%%.%df", pSystemSetting->GetDecimalSize());
csText.Format(buffer, iterpart->GetSize());
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::BID_SIZE, csText);
memset(&buffer, 0, sizeof(buffer));
sprintf(buffer, "%%.%df", pSystemSetting->GetDecimalPrice());
csText.Format(buffer, iter->GetPrice());
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::BID_PRICE, csText);
if (sizeof(iterpart->GetTimestamp().c_str()) > 255)
continue;
csText.Format("%s", iterpart->GetTimestamp().c_str());
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::BID_TIME, csText);
}
}
}
const std::vector<CMarketData> & userListAsk =
pInstData->GetMarketDataAsk();
for (iter = userListAsk.begin(); iter != userListAsk.end(); iter++)
{
const std::vector<CParticipant> & participants =
iter->GetParticipants();
for (iterpart = participants.begin(); iterpart != participants.end();
iterpart++)
{
if (iterpart->GetSize() > 0.0 && iter->GetPrice() > 0.0)
{
memset(&buffer, 0, sizeof(buffer));
if (sizeof(iterpart->GetUserName()/*.c_str()*/) > 255)
continue;
//sprintf(buffer, "%s", iterpart->GetUserName()/*.c_str()*/);
int size = iterpart->GetUserName().GetLength();
char bufsize[20];
memset(&bufsize, 0, sizeof(bufsize));
_itoa(size,bufsize,10);
CUtility::LogDebugInfo( "OnNotifyNewData - ASK UserName", bufsize);
info.psz = iterpart->GetUserName();
iIndex = m_ctrlUserListCtrl.FindItem(&info);
if (iIndex == -1)
{ // insert the item
iIndex = m_ctrlUserListCtrl.GetItemCount();
if (sizeof(iterpart->GetUserName()/*.c_str()*/) > 255)
continue;
//csText.Format(TEXT("%s"), iterpart->GetUserName()/*.c_str()*/);
csText = iterpart->GetUserName();
m_ctrlUserListCtrl.InsertItem(LVIF_TEXT|LVIF_STATE, iIndex, csText,
0, LVIS_SELECTED, 0, 0);
char * pchText = new char [csText.GetLength() + 1];
strcpy(pchText, (LPCTSTR)csText);
m_ctrlUserListCtrl.SetItemData(iIndex, (DWORD)pchText);
}
if (sizeof(pInstData->GetInstName()/*.c_str()*/) > 255)
continue;
//csText.Format(TEXT("%s"), pInstData->GetInstName().c_str());
csText = pInstData->GetInstName();
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::ASK_INST, csText);
memset(&buffer, 0, sizeof(buffer));
sprintf(buffer, "%%.%df", pSystemSetting->GetDecimalSize());
csText.Format(buffer, iterpart->GetSize());
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::ASK_SIZE, csText);
memset(&buffer, 0, sizeof(buffer));
sprintf(buffer, "%%.%df", pSystemSetting->GetDecimalPrice());
csText.Format(buffer, iter->GetPrice());
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::ASK_PRICE, csText);
if (sizeof(iterpart->GetTimestamp().c_str()) > 255)
continue;
csText.Format("%s", iterpart->GetTimestamp().c_str());
m_ctrlUserListCtrl.SetItemText(iIndex,
eUserViewListColumn::ASK_TIME, csText);
}
}
}
VERIFY(m_ctrlUserListCtrl.SortItems( CompareFunction, r

WRITE_LOG_FUNCTION_EXIT("LRESULT
CUserViewFrame::OnNotifyNewData (WPARAM wParam,
PARAM
lParam)")
const char* strVariable1("CUserViewFrame::OnNotifyNewData END");
CUtility::LogDebugInfo( strVariable1, strValue);
return 0;
}
Is there any chance the sprintf or CString Format function is creating
this problem.
I have spent lot of time it undertsanding this bug with no success. Any
help would be greatly appreciated.
Regards,
Sandy- Hide quoted text -- Show quoted text -
 
Top