000
29.09.2005, 10:36 Uhr
commanderberry
|
Hallo,
ich lese ein Unicode Logfile mit CFile::Read aus. im alten VC6 lief alles problemlos, nur jetzt im VC7 meckert er beim Verlassen der function und sagt folgendes:
run-time check failure #2 - stack around the variable buffer was corrupted
da ich unicode auslese, habe ich den buffer auf die hälfte der auszulesenden bytes gesetzt, da ein unicode zeichen ja 2 bytes hat. ich denke es hängt irgendwie damit zusammen.. hat jemand eine idee? ich weiß echt nicht mehr weiter! Hier mal der gesamte code:
C++: |
void CCompDoc::ReadFileIntoDataStructure(CFile* pFile, CString sDisplayName, COLORREF crFontColor) { DWORD dwRead; const unsigned int iBufferSize = 256; wchar_t buffer[iBufferSize/2]; wcsset(buffer,0); int len = wcslen(buffer); CString sTarget; //(buffer); CString tmp =""; int crPos;
LogFile *lFile = new LogFile(); BOOL ok = TRUE; dwRead = pFile->Read(buffer, 2); //liest die ersten 2 BYTES aus --> UNICODE Kennzeichen int counter=0; do { dwRead = pFile->Read(buffer, iBufferSize); sTarget+= _T(buffer); if (dwRead<iBufferSize) { /* this is only for the last read operation, where dwRead<iBufferSize in this case the last (unnecessary) chars will be removed */ sTarget = sTarget.Left(sTarget.GetLength() - (iBufferSize - dwRead)/2); if (dwRead==0) //adds an additional linebreal and eof-->make sure to get last line sTarget = sTarget + (char(13)) + ((char)10); } do { while ((sTarget.GetLength()>0) && ((sTarget.GetAt(0)==13) || (sTarget.GetAt(0)==10))) { /* removes the chars for value 10 or 13 (linebreak) until the first charvalue is unequal to (char) 10 or (char)13 */ sTarget.Delete(0, 1); } // look up for linebreak crPos = sTarget.Find((char)13, 0); if (crPos!=-1) { // if linebreak found add all chars until linebreak-position // as a entry in current logfile tmp = sTarget.Mid(0, crPos); sTarget.Delete(0, crPos); if (lFile->AddEntry(tmp) == TRUE) { counter++; } else { AfxMessageBox("Error converting time-value in this Line:\n" + tmp + "\n" + "in File: " + sDisplayName); } } } while (crPos!=-1); } while (dwRead>0);
lFile->SetTotalEntries(counter); lFile->SetFileName(pFile->GetFilePath()); lFile->SetDisplayName(sDisplayName); lFile->SetFontColor(crFontColor); lFile->SetVisible(TRUE); m_oaLogFiles.Add(lFile); m_iOpenLogFileCounter++; //wcsset(buffer,0);
}
|
Vieln Dank schonmal! |