Commit d62c9852 authored by Alexander Smorkalov's avatar Alexander Smorkalov

Invalid usage of cv::Ptr for arrays fixed.

parent 449b99a6
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
namespace cv namespace cv
{ {
std::vector<std::string> Directory::GetListFiles( const std::string& path, const std::string & exten, bool addPath ) std::vector<std::string> Directory::GetListFiles( const std::string& path, const std::string & exten, bool addPath )
{ {
std::vector<std::string> list; std::vector<std::string> list;
list.clear(); list.clear();
...@@ -25,10 +25,9 @@ namespace cv ...@@ -25,10 +25,9 @@ namespace cv
HANDLE hFind; HANDLE hFind;
#ifdef HAVE_WINRT #ifdef HAVE_WINRT
size_t size = mbstowcs(NULL, path_f.c_str(), path_f.size()); wchar_t wpath[MAX_PATH];
Ptr<wchar_t> wpath = new wchar_t[size+1]; size_t copied = mbstowcs(wpath, path_f.c_str(), MAX_PATH);
wpath[size] = 0; CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
mbstowcs(wpath, path_f.c_str(), path_f.size());
hFind = FindFirstFileExW(wpath, FindExInfoStandard, &FindFileData, FindExSearchNameMatch, NULL, 0); hFind = FindFirstFileExW(wpath, FindExInfoStandard, &FindFileData, FindExSearchNameMatch, NULL, 0);
#else #else
hFind = FindFirstFileA((LPCSTR)path_f.c_str(), &FindFileData); hFind = FindFirstFileA((LPCSTR)path_f.c_str(), &FindFileData);
...@@ -47,12 +46,12 @@ namespace cv ...@@ -47,12 +46,12 @@ namespace cv
FindFileData.dwFileAttributes == FILE_ATTRIBUTE_SYSTEM || FindFileData.dwFileAttributes == FILE_ATTRIBUTE_SYSTEM ||
FindFileData.dwFileAttributes == FILE_ATTRIBUTE_READONLY) FindFileData.dwFileAttributes == FILE_ATTRIBUTE_READONLY)
{ {
cv::Ptr<char> fname; char* fname;
#ifdef HAVE_WINRT #ifdef HAVE_WINRT
size_t asize = wcstombs(NULL, FindFileData.cFileName, 0); char fname_tmp[MAX_PATH] = {0};
fname = new char[asize+1]; size_t copied = wcstombs(fname_tmp, FindFileData.cFileName, MAX_PATH);
fname[asize] = 0; CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
wcstombs(fname, FindFileData.cFileName, asize); fname = fname_tmp;
#else #else
fname = FindFileData.cFileName; fname = FindFileData.cFileName;
#endif #endif
...@@ -109,10 +108,10 @@ namespace cv ...@@ -109,10 +108,10 @@ namespace cv
HANDLE hFind; HANDLE hFind;
#ifdef HAVE_WINRT #ifdef HAVE_WINRT
size_t size = mbstowcs(NULL, path_f.c_str(), path_f.size()); wchar_t wpath [MAX_PATH];
Ptr<wchar_t> wpath = new wchar_t[size+1]; size_t copied = mbstowcs(wpath, path_f.c_str(), path_f.size());
wpath[size] = 0; CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
mbstowcs(wpath, path_f.c_str(), path_f.size());
hFind = FindFirstFileExW(wpath, FindExInfoStandard, &FindFileData, FindExSearchNameMatch, NULL, 0); hFind = FindFirstFileExW(wpath, FindExInfoStandard, &FindFileData, FindExSearchNameMatch, NULL, 0);
#else #else
hFind = FindFirstFileA((LPCSTR)path_f.c_str(), &FindFileData); hFind = FindFirstFileA((LPCSTR)path_f.c_str(), &FindFileData);
...@@ -135,12 +134,12 @@ namespace cv ...@@ -135,12 +134,12 @@ namespace cv
strcmp(FindFileData.cFileName, "..") != 0) strcmp(FindFileData.cFileName, "..") != 0)
#endif #endif
{ {
cv::Ptr<char> fname; char* fname;
#ifdef HAVE_WINRT #ifdef HAVE_WINRT
size_t asize = wcstombs(NULL, FindFileData.cFileName, 0); char fname_tmp[MAX_PATH];
fname = new char[asize+1]; size_t copied = wcstombs(fname, FindFileData.cFileName, MAX_PATH);
fname[asize] = 0; CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
wcstombs(fname, FindFileData.cFileName, asize); fname = fname_tmp;
#else #else
fname = FindFileData.cFileName; fname = FindFileData.cFileName;
#endif #endif
......
...@@ -79,10 +79,9 @@ namespace ...@@ -79,10 +79,9 @@ namespace
dir->ent.d_name = 0; dir->ent.d_name = 0;
#ifdef HAVE_WINRT #ifdef HAVE_WINRT
cv::String full_path = cv::String(path) + "\\*"; cv::String full_path = cv::String(path) + "\\*";
size_t size = mbstowcs(NULL, full_path.c_str(), full_path.size()); wchar_t wfull_path[MAX_PATH];
cv::Ptr<wchar_t> wfull_path = new wchar_t[size+1]; size_t copied = mbstowcs(wfull_path, full_path.c_str(), MAX_PATH);
wfull_path[size] = 0; CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
mbstowcs(wfull_path, full_path.c_str(), full_path.size());
dir->handle = ::FindFirstFileExW(wfull_path, FindExInfoStandard, dir->handle = ::FindFirstFileExW(wfull_path, FindExInfoStandard,
&dir->data, FindExSearchNameMatch, NULL, 0); &dir->data, FindExSearchNameMatch, NULL, 0);
#else #else
...@@ -106,6 +105,7 @@ namespace ...@@ -106,6 +105,7 @@ namespace
return 0; return 0;
} }
size_t asize = wcstombs(NULL, dir->data.cFileName, 0); size_t asize = wcstombs(NULL, dir->data.cFileName, 0);
CV_Assert((asize != 0) && (asize != (size_t)-1));
char* aname = new char[asize+1]; char* aname = new char[asize+1];
aname[asize] = 0; aname[asize] = 0;
wcstombs(aname, dir->data.cFileName, asize); wcstombs(aname, dir->data.cFileName, asize);
...@@ -146,10 +146,9 @@ static bool isDir(const cv::String& path, DIR* dir) ...@@ -146,10 +146,9 @@ static bool isDir(const cv::String& path, DIR* dir)
{ {
WIN32_FILE_ATTRIBUTE_DATA all_attrs; WIN32_FILE_ATTRIBUTE_DATA all_attrs;
#ifdef HAVE_WINRT #ifdef HAVE_WINRT
size_t size = mbstowcs(NULL, path.c_str(), path.size()); wchar_t wpath[MAX_PATH];
cv::Ptr<wchar_t> wpath = new wchar_t[size+1]; size_t copied = mbstowcs(wpath, path.c_str(), MAX_PATH);
wpath[size] = 0; CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
mbstowcs(wpath, path.c_str(), path.size());
::GetFileAttributesExW(wpath, GetFileExInfoStandard, &all_attrs); ::GetFileAttributesExW(wpath, GetFileExInfoStandard, &all_attrs);
#else #else
::GetFileAttributesExA(path.c_str(), GetFileExInfoStandard, &all_attrs); ::GetFileAttributesExA(path.c_str(), GetFileExInfoStandard, &all_attrs);
......
...@@ -411,15 +411,14 @@ string tempfile( const char* suffix ) ...@@ -411,15 +411,14 @@ string tempfile( const char* suffix )
temp_file = temp_dir + std::wstring(L"\\") + temp_file; temp_file = temp_dir + std::wstring(L"\\") + temp_file;
DeleteFileW(temp_file.c_str()); DeleteFileW(temp_file.c_str());
size_t asize = wcstombs(NULL, temp_file.c_str(), 0); char aname[MAX_PATH];
Ptr<char> aname = new char[asize+1]; size_t copied = wcstombs(aname, temp_file.c_str(), MAX_PATH);
aname[asize] = 0; CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
wcstombs(aname, temp_file.c_str(), asize);
fname = std::string(aname); fname = std::string(aname);
RoUninitialize(); RoUninitialize();
#else #else
char temp_dir2[MAX_PATH + 1] = { 0 }; char temp_dir2[MAX_PATH] = { 0 };
char temp_file[MAX_PATH + 1] = { 0 }; char temp_file[MAX_PATH] = { 0 };
if (temp_dir == 0 || temp_dir[0] == 0) if (temp_dir == 0 || temp_dir[0] == 0)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment