![]() |
|
![]() ![]() ![]() |
|
StrikeTheCore |
|
|||
Новичок Профиль Группа: Участник Сообщений: 11 Регистрация: 25.5.2006 Репутация: нет Всего: нет |
I have code running that constantly throws an Access Violation on Windows XP. This exception only occurs however after around 10 to 20 thousand times running this function. I can catch the exception but want to get rid of it completely, however cannot figure out where it is coming from. Code is below (str is a simple string parser). Any help is greatly appreciated.
//-------------------------------------------------------- unsigned char *inbuffer; AnsiString tmp; struct timeval current; inbuffer = new unsigned char[Count+2]; myComPort->Read(inbuffer, Count); str.reset(); try { if(Form2->mode == TForm2::HEX_MODE && !Form2->BufferDisabled->Checked){ for(int i=0; i<Count; i++){ tmp.sprintf("%0x ", inbuffer[i]); if(tmp.Length() < 3) tmp = AnsiString("0") + tmp; str << tmp.c_str() << " "; } if(Form2->ReceiveBuffer.Length() + str.length() < Form2->MaxBufLen){ Form2->ReceiveBuffer += AnsiString(str.c_str()).UpperCase(); } else{ unsigned int n=0; for(int count=0;n<=str.length();count++) n += (*(Form2->Memo->Lines))[count].Length(); Form2->ReceiveBuffer.Delete(0, n); Form2->ReceiveBuffer += AnsiString(str.c_str()).UpperCase(); } } else if(Form2->mode == TForm2::ASCII_MODE && !Form2->BufferDisabled->Checked){ inbuffer[Count] = '\0'; if(Form2->ReceiveBuffer.Length() + strlen((char*)inbuffer) > Form2->MaxBufLen){ Form2->ReceiveBuffer.Delete(0, strlen((char*)inbuffer)); } Form2->ReceiveBuffer += AnsiString((char*)inbuffer); if(Form2->logdata){ std::ofstream outfile; outfile.open(Form2->LogFileName.c_str(), std::ofstream::out | std::ofstream::app); outfile << (char*)inbuffer; outfile.close(); } } } catch (const EAccessViolation & vae) { ShowMessage("Misread message"); } |
|||
|
||||
Vyacheslav |
|
|||
Эксперт ![]() ![]() ![]() ![]() Профиль Группа: Экс. модератор Сообщений: 2124 Регистрация: 25.3.2002 Где: Москва Репутация: 47 Всего: 59 |
Is Form2->ReceiveBuffer AnsiString? If this is AnsiString, the first argument in Delete has to be larger than 0 and less than Length of the AnsiString. See help
-------------------- С уважением, Вячеслав Ермолаев |
|||
|
||||
StrikeTheCore |
|
|||
Новичок Профиль Группа: Участник Сообщений: 11 Регистрация: 25.5.2006 Репутация: нет Всего: нет |
Thanks a lot, that solved the problem. I guess I'm so used to Java and string indexes starting at 0 that I didn't even consider the possibility that this could be the source of the problem.
|
|||
|
||||
![]() ![]() ![]() |
Правила форума "С++ Builder" | |
|
Запрещается! 1. Публиковать ссылки на вскрытые компоненты 2. Обсуждать взлом компонентов и делиться вскрытыми компонентами
Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, Rrader. |
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей) | |
0 Пользователей: | |
« Предыдущая тема | C++ Builder | Следующая тема » |
|
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности Powered by Invision Power Board(R) 1.3 © 2003 IPS, Inc. |