summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Nathan Woods <npwoods@mess.org>2016-07-25 07:49:26 -0400
committer Nathan Woods <npwoods@mess.org>2016-07-25 07:49:26 -0400
commit4a9e9742fde15b835709137b81cae1223d1f69d7 (patch)
tree653764538541936b4b188737d7cd6b2d0c86d8d4
parentab73291e479be171d6f89798ed706b5ea58aa09f (diff)
Fixed off by one issue and other cleanups requested by Vas
-rw-r--r--src/osd/modules/file/winfile.cpp27
-rw-r--r--src/osd/modules/font/font_windows.cpp2
-rw-r--r--src/osd/modules/lib/osdlib_win32.cpp2
-rw-r--r--src/osd/strconv.cpp4
4 files changed, 16 insertions, 19 deletions
diff --git a/src/osd/modules/file/winfile.cpp b/src/osd/modules/file/winfile.cpp
index 1484caeb818..1f85fc15645 100644
--- a/src/osd/modules/file/winfile.cpp
+++ b/src/osd/modules/file/winfile.cpp
@@ -116,17 +116,6 @@ private:
};
-template <typename T>
-class osd_disposer
-{
-public:
- osd_disposer(T *&ptr) : m_ptr(ptr) { }
- ~osd_disposer() { if (m_ptr) osd_free(m_ptr); }
-private:
- T *&m_ptr;
-};
-
-
//============================================================
// INLINE FUNCTIONS
@@ -186,6 +175,11 @@ osd_file::error osd_file::open(std::string const &orig_path, UINT32 openflags, p
// convert path to TCHAR
auto t_path = tstring_from_utf8(path.c_str());
+ // convert the path into something Windows compatible (the actual interesting part appears
+ // to have been commented out???)
+ for (auto iter = t_path.begin(); iter != t_path.end(); iter++)
+ *iter = /* ('/' == *iter) ? '\\' : */ *iter;
+
// select the file open modes
DWORD disposition, access, sharemode;
if (openflags & OPEN_FLAG_WRITE)
@@ -213,13 +207,16 @@ osd_file::error osd_file::open(std::string const &orig_path, UINT32 openflags, p
// create the path if necessary
if ((ERROR_PATH_NOT_FOUND == err) && (openflags & OPEN_FLAG_CREATE) && (openflags & OPEN_FLAG_CREATE_PATHS))
{
- TCHAR *pathsep = _tcsrchr(&t_path[0], '\\');
- if (pathsep != nullptr)
+ // the code below assumes these are the same
+ assert(std::string::npos == std::wstring::npos);
+
+ auto pathsep = t_path.rfind('\\');
+ if (pathsep != std::string::npos)
{
// create the path up to the file
- *pathsep = 0;
+ t_path[pathsep] = 0;
err = create_path_recursive(&t_path[0]);
- *pathsep = '\\';
+ t_path[pathsep] = '\\';
// attempt to reopen the file
if (err == NO_ERROR)
diff --git a/src/osd/modules/font/font_windows.cpp b/src/osd/modules/font/font_windows.cpp
index 707cb8ef5d0..384e6fe8505 100644
--- a/src/osd/modules/font/font_windows.cpp
+++ b/src/osd/modules/font/font_windows.cpp
@@ -86,7 +86,7 @@ bool osd_font_windows::open(std::string const &font_path, std::string const &_na
// copy in the face name
std::basic_string<TCHAR> face = tstring_from_utf8(name.c_str());
- _tcsncpy(logfont.lfFaceName, face.c_str(), sizeof(logfont.lfFaceName) / sizeof(TCHAR));
+ _tcsncpy(logfont.lfFaceName, face.c_str(), ARRAY_LENGTH(logfont.lfFaceName));
logfont.lfFaceName[sizeof(logfont.lfFaceName) / sizeof(TCHAR)-1] = 0;
// create the font
diff --git a/src/osd/modules/lib/osdlib_win32.cpp b/src/osd/modules/lib/osdlib_win32.cpp
index f69ad5050d2..b9f647d3bbb 100644
--- a/src/osd/modules/lib/osdlib_win32.cpp
+++ b/src/osd/modules/lib/osdlib_win32.cpp
@@ -277,7 +277,7 @@ static char *get_clipboard_text_by_format(UINT format, std::string (*convert)(LP
// copy the string
result = (char *) osd_malloc(s.size() + 1);
if (result != nullptr)
- memcpy(result, s.data(), s.size() * sizeof(*result));
+ memcpy(result, s.data(), (s.size() + 1) * sizeof(*result));
// unlock the data
GlobalUnlock(data_handle);
diff --git a/src/osd/strconv.cpp b/src/osd/strconv.cpp
index 88e8d4a1b8b..3919dddbf18 100644
--- a/src/osd/strconv.cpp
+++ b/src/osd/strconv.cpp
@@ -25,9 +25,9 @@ std::string &astring_from_utf8(std::string &dst, const char *s)
std::basic_string<WCHAR> wstring = wstring_from_utf8(s);
// convert UTF-16 to "ANSI code page" string
- int char_count = WideCharToMultiByte(CP_ACP, 0, wstring.c_str(), -1, nullptr, 0, nullptr, nullptr);
+ int char_count = WideCharToMultiByte(CP_ACP, 0, wstring.c_str(), wstring.size() + 1, nullptr, 0, nullptr, nullptr);
dst.resize(char_count - 1);
- WideCharToMultiByte(CP_ACP, 0, wstring.c_str(), -1, &dst[0], char_count - 1, nullptr, nullptr);
+ WideCharToMultiByte(CP_ACP, 0, wstring.c_str(), wstring.size() + 1, &dst[0], char_count - 1, nullptr, nullptr);
return dst;
}