Here I have a function that sends a request to a server to delete a file. But, it always crashes on a certain line when compiled in debug mode and runs fine when compiled in release mode. Is this a compiler error? Here's my code:
It always crashes between the 2 last messageboxes, right after I click ok on the "Going to delete fNameBuf". The crash thing that pops up says:Code:void deleteFile(HWND hWnd) { //Get a handle to the listbox control HWND lb = GetDlgItem(hWnd, IDC_REMOTEFILES); //lb = listbox //Get the index of the listbox item int index = SendMessage(lb, LB_GETCURSEL, 0, 0); //Get the length of the item and allocate a string for it int len = SendMessage(lb, LB_GETTEXTLEN, index, 0); char* fNameBuf = new char[len]; unsigned char nameLen = SendMessage(lb, LB_GETTEXT, index, (LPARAM)fNameBuf); unsigned long msgLen = 1; msgLen += sizeof(nameLen); msgLen += nameLen; server->send(htonl(msgLen)); server->send(ICV_OP_DELETE); server->send(nameLen); server->send(fNameBuf); unsigned char result; server->receive((char*)&result, 1); if(result == ICV_SR_ERR) MessageBox(hWnd, "File could not be deleted.", "Error", MB_OK); else if(result == ICV_SR_OK) MessageBox(hWnd, "File successfully deleted.", "Success", MB_OK); else MessageBox(hWnd, "Unknown protocol error.", "Error", MB_OK); MessageBox(hWnd, "Going to delete fNameBuf", "c", MB_OK); delete[] fNameBuf; MessageBox(hWnd, "fNameBuf deleted", "k", MB_OK); }
Should I look to my code or my compiler for the problem? I really can't see anything wrong with the code, but I thought I'd ask just in case, since it's just about always my fault anywaysDebug error!
Program: (...)
Damage: after Normal block (#22) at 0x00F10D90
(abort, retry, ignore)
**EDIT**
Wasn't sure if this belonged on the c++, networking, or Windows board, but since the code involves Windows API I thought I'd put it under Windows... hope the mods don't mind.



LinkBack URL
About LinkBacks




Guess I better be tracking that bounds overflow thinger down now 
