Необработанное исключение по адресу 0x7650C41F в файле binary.exe: Исключение Microsoft C++: std::bad_alloc в ячейке памяти 0x003EEE00.
First-chance exception at 0x77983AB3 (ntdll.dll) in binary.exe: 0xC0000005: Access violation reading location 0x6F726369.
First-chance exception at 0x7650C41F in binary.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x003DF0DC.
First-chance exception at 0x7650C41F in binary.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x003DF0DC.
First-chance exception at 0x77983AB3 (ntdll.dll) in binary.exe: 0xC0000005: Access violation reading location 0x6F726369.
First-chance exception at 0x7650C41F in binary.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x003DEA40.
First-chance exception at 0x7650C41F in binary.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x003DEA40.
First-chance exception at 0x7650C41F in binary.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
First-chance exception at 0x7650C41F in binary.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
Unhandled exception at at 0x7650C41F in binary.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x003DEA40.
The program '[7632] binary.exe' has exited with code 0 (0x0).
Я не знаю, совершаю ли я ошибку новичка, но каждый раз, когда я пытаюсь запустить приведенный ниже код, я получаю ошибки, перечисленные выше - из того, что я могу собрать из различных сообщений на форуме и сообщений об ошибках, есть проблема с распределение памяти, но это все, что у меня есть.
Приведенный ниже код является укороченной версией моего проекта, так как исходные файлы довольно длинные и их не нужно публиковать.
int _tmain(int argc, _TCHAR* argv[])
{
check(true);
system("pause");
return 0;
}
int check(bool initialCheck)
{
char* path = getDocumentRootA(); strcat(path, "Test//file.test");
char* filePathA = getDocumentRootA(); strcat(filePathA, "Test2\\file.test");
char* filePathB = getDocumentRootA(); strcat(filePathB, "Test3\\file.test");
cout << "Checking if files exists...";
if (doesFileExist(path) == true)
{
cout << "Yes\n";
} else if (doesFileExist(path) == false) {
cout << "No\n"; // todo
}
cout << "Checking if other files exist...";
if (doesFileExist(filePathA) == true && doesFileExist(filePathB) == true)
{
cout << "Yes\n";
}
return 0;
}
char* getDocumentRootA()
{
CHAR documentRootC[MAX_PATH]; CA2W uDocumentRoot(documentRootC);
HRESULT result = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, uDocumentRoot); CW2A documentRoot_T(uDocumentRoot); strcat(documentRoot_T, "\\");
string documentRootTemp = documentRoot_T; char* documentRoot = const_cast<char*>(documentRootTemp.c_str());
cout<<documentRoot;
return documentRoot;
}
Вероятно, также стоит отметить, что я попытался изменить первую часть кода (см. пример ниже), чтобы функция getDocumentRootA()
вызывалась только один раз, но это не решило проблему.
char* testvar = getDocumentRootA();
char* path = testvar; strcat(path, "Microsoft\\file.test");
char* filePathA = testvar; strcat(filePathA, "Windows\\AppLoc\\file.test");
char* filePathB = testvar; strcat(filePathB, "Windows\\U\\file.test");