diff --git a/src/depressed_document.cpp b/src/depressed_document.cpp index 7ff0a82..e65432d 100644 --- a/src/depressed_document.cpp +++ b/src/depressed_document.cpp @@ -330,7 +330,14 @@ namespace Depressed { } } else if(read == ERead::PAGES) { if(wcscmp(value, L"Page") == 0) { - CPage *page = new CPage(); + CPage *page; + + try { + page = new CPage(); + } catch (std::bad_alloc) { + success = false; + break; + } page->Create(); diff --git a/src/depressed_open.cpp b/src/depressed_open.cpp index 0a9508c..bf56376 100644 --- a/src/depressed_open.cpp +++ b/src/depressed_open.cpp @@ -152,15 +152,15 @@ namespace Depressed { IXmlWriter *writer; IStream *filestream; - dirptr = wcschr(filename, '/'); + dirptr = wcsrchr(filename, '/'); if(dirptr) { wchar_t *dirptr2; - dirptr2 = wcschr(dirptr, '\\'); + dirptr2 = wcsrchr(dirptr, '\\'); if(dirptr2) dirptr = dirptr2; } else - dirptr = wcschr(filename, '\\'); + dirptr = wcsrchr(filename, '\\'); if(dirptr) { size_t len; diff --git a/src/depressed_page.cpp b/src/depressed_page.cpp index 8e226d4..a908612 100644 --- a/src/depressed_page.cpp +++ b/src/depressed_page.cpp @@ -153,15 +153,17 @@ namespace Depressed { hr = writer->WriteString(m_filename); else { size_t basepath_len; - wchar_t *filename; + wchar_t *filename = m_filename; basepath_len = wcslen(basepath); - filename = m_filename + basepath_len; - while(*filename) { - if(*filename == '\\' || *filename == '/') - filename++; - else - break; + if(wcsncmp(basepath, filename, basepath_len) == 0) { + filename += basepath_len; + while(*filename) { + if(*filename == '\\' || *filename == '/') + filename++; + else + break; + } } hr = writer->WriteString(filename);