Ok i have been looking at this block of code for about 2 weeks and cant figure out why my program keep on crashing within this block of code if you could help thanks -
void __fastcall TPSM_OperatorClientForm::csktClientSocketRead(
-
TObject *Sender, TCustomWinSocket *Socket)
-
{
-
try
-
{
-
bool done = false;
-
int bytes = 0;
-
static int bytesLeft = 0;
-
int msgBytes = 0;
-
int offset = 0;
-
struct PSM_Message *msg = 0;
-
-
// Allocate memory to receive message
-
static char *ptr;
-
static char buf[MAX_SIZE];
-
ptr = buf;
-
-
// Read the message from the socket
-
bytes = Socket->ReceiveBuf((void*)(ptr + bytesLeft), (MAX_SIZE - bytesLeft));
-
-
// Set the bytes left value
-
bytesLeft += bytes;
-
-
// Are there messages to be dispatched
-
int iTotalLen = 0;
-
while(1)
-
{
-
void *cpyBuff = 0;
-
-
// Get the 1st message
-
msg = (struct PSM_Message *)&(ptr[offset]);
-
msgBytes = msg->m_size;
-
-
if(bytesLeft < msgBytes)//badri
-
return;
-
-
// Allocate copy buffer for message
-
cpyBuff = calloc(msg->m_size, sizeof(char));
-
-
if( cpyBuff == NULL)
-
return;
-
-
// Copy the 1st message to the copy buffer
-
::memmove((void *)cpyBuff, (const void *)&(ptr[offset]), sizeof(char) * msgBytes);
-
iTotalLen += sizeof(char) * msgBytes;
-
-
// Move the offset
-
offset += msg->m_size;
-
-
if(msg->m_messageID == MSG_SM_OC_DATABASE_PATH_INFO)
-
{
-
WriteLog("OperatorCLientForm : Connected to server received - MSG_SM_OC_DATABASE_PATH_INFO");
-
LogonRequest(msg);
-
free(cpyBuff);
-
}
-
else
-
{
-
if (!::PostThreadMessage(pRouterThread->ThreadID, msg->m_messageID, (WPARAM)cpyBuff, 0))
-
{
-
//Savita 11/dec/2001
-
AnsiString str = " PostMsgFailed its all down hill from here --The Error Code returned " + AnsiString(GetLastError());
-
WriteLog(L_ERROR,str.c_str());
-
//If it has not deleted also create this thread inorder to maintain the continuity
-
pRouterThread = NULL;
-
pRouterThread = new PSM_RouterThread(false);
-
-
//Viswanath 12/dec/2001
-
if(pRouterThread != NULL)
-
{
-
WriteLog("OperatorCLientForm : Creating New Router Thread");
-
}
-
else
-
{
-
//Display a message stating that the resources is low. Shut down OC gracefully
-
//MessageBox(Handle,"System running low on resources.....Shutting down Operator Client","MMPOSEM Error",MB_OK |MB_SYSTEMMODAL );
-
MessageBox(Handle,GetString(IDS_ERR_SYSTEM_LOW_RESOURCES).c_str(),
-
GetString(IDS_ERR_IPOS_ERROR).c_str(),
-
MB_OK |MB_SYSTEMMODAL );
-
exit(-1);
-
}
-
}
-
}
-
-
// adjust the bytes left value
-
bytesLeft -= msg->m_size;
-
if (bytesLeft < 0) bytesLeft = 0;
-
-
// Check to see if we have dispatched ALL the messages in the buffer
-
if(bytesLeft < 1) //badri
-
{
-
::memmove((void *)ptr, (const void *)&(ptr[iTotalLen]), sizeof(char) * bytesLeft);
-
return;
-
}
-
-
// Reset locals
-
cpyBuff = 0;
-
msg = 0;
-
-
}
-
// Free the Rx buffer
-
// free(ptr);
-
-
#ifdef COMMOUT
-
//Process the message
-
try
-
{
-
if ( msg->m_messageID == MSG_SM_OC_DATABASE_PATH_INFO )
-
{
-
WriteLog("OperatorCLientForm : Connected to server received - MSG_SM_OC_DATABASE_PATH_INFO");
-
LogonRequest(msg);
-
}
-
else
-
{
-
::PostThreadMessage(pRouterThread->ThreadID, msg->m_messageID, (WPARAM)msg,0);
-
}
-
}
-
catch(...)
-
{
-
//ShowMessage("Server not located");
-
ShowMessage( GetString(ID_SVR_NOT_LOC) );
-
PSM_TransFilterForm->TransGridHeaderDisplay();
-
}
-
#endif
-
}
-
catch(...)
-
{
-
WriteLog(L_ERROR,"TPSM_OperatorClientForm :: csktClientSocketRead Failed ");
-
}
-
}
3 1459
The piece of source is much too long. Please remove all parts that are
definitly not responsible for the crash and post again. You probably even find
your mistake yourself then.
The piece of source is much too long. Please remove all parts that are
definitly not responsible for the crash and post again. You probably even find
your mistake yourself then.
Agreed.
Adrian
I Have narrowed it down to these lines of code that are causing the my program to crash now i have commented out the if statement and noticed that it the program will run a lot longer but it will eventually crash if any one can help me figure out how i can fix this i will be very grateful it thanks -
if(bytesLeft < 8000000)
-
{
-
::memmove((void *)ptr, (const void *)&(ptr[iTotalLen]), sizeof(char) * bytesLeft);
-
return;
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics
by: J. Campbell |
last post by:
what happens to allocated memory when a program terminates before the
memory is released. For example:
int main(){
int* array;
int a_size = 1000;
array = new int;
for(int i = 0; i < a_size;...
|
by: Steven |
last post by:
The following program runs alright until the return statement, where it
crashes, and consequently, Dr. Watson (drwtsn32.exe) also crashes.
Deleting the call to fgets() and everything runs fine. I...
|
by: Paul Bromley |
last post by:
I am about to release the second version of a program that I started writing
12 months ago. The first version worked fine on 98 upwards. This version
seems to crash on Windows 98. I realise that...
|
by: popone |
last post by:
Hi All,
I've developed a program that seems to crash randomly, from what I can
tell it's after some user action. If it just sat there, it wouldn't
crash. It's not an exception either, it's the...
|
by: Daniel |
last post by:
I am baffled. According to the C++ faq lite it is ok to use a reference
as an lvalue, and the subscript operator returns a reference. However,
when I run this program, it crashes!
I will go set up...
|
by: z |
last post by:
I use Visual C 2005 to develop my programs. One in particular is
crashing in very specific and hard to replicate situations, made worse
by the fact it only crashes when run -outside- the dev - as...
|
by: linksterman |
last post by:
I am coding for the PSP and I have an RSS reader that will show images and stuff. the proplem is that the reader will crash after displaying i think 10 pages with images on them. here is the part of...
|
by: Deviate |
last post by:
Hi guys, my first post here, im desperately in need of help! :)
When i am running Visual C++ 6.0 and have my .cpp file opened, i compile, build and run the program, it all works fine. But if i...
|
by: Thomas Neubauer |
last post by:
Hello,
i am learning c# and have created now a simple project that just creates 6
random numbers.
My form includes a button and 6 labels for the random numbers. The program
seems to work...
|
by: jaddle |
last post by:
I program I'm writing crashes when it exits with a segfault. I'm runnning under linux. Using gdb, i see that the crash happens after the last line of main(), which is just a return(EXIT_SUCCESS); If...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |