OSDN Git Service

PATCH: [ 2008581 ] Convert paths using system codepage
authorKimmo Varis <kimmov@gmail.com>
Tue, 8 Jul 2008 23:10:58 +0000 (23:10 +0000)
committerKimmo Varis <kimmov@gmail.com>
Tue, 8 Jul 2008 23:10:58 +0000 (23:10 +0000)
 Fixed memory handling, problem(s) noticed by Jochen

Docs/Users/ChangeLog.txt
Src/AnsiConvert.cpp
Src/DiffFileData.cpp
Src/DiffWrapper.cpp
Src/DirCmpReport.cpp

index 2cc9b24..eb2b943 100644 (file)
@@ -6,6 +6,7 @@ http://winmerge.org/tracker/[tracker-id]
 WinMerge 2.11.1.1
   Manual: Introduction update (#2011365)
   Add ShellExtension menu for drive letters (root folders) (#2011602)
+  BugFix: Use system codepage for paths (#1979429, #2008581)
 
 WinMerge 2.10.x (R2_10) branch created (r5561)
 
index e967638..4196671 100644 (file)
@@ -7,7 +7,9 @@
 // ID line follows -- this is updated by SVN
 // $Id$
 
-#include "stdafx.h"
+#include <windows.h>
+
+static LPCSTR convert(LPCTSTR str, UINT codepage);
 
 /**
  * @brief Convert from Unicode to Ansi using system codepage.
  */
 LPCSTR ansiconvert_SystemCP(LPCTSTR str)
 {
-       // These lines replace USES_CONVERSION macro
-       int _convert = 0;
-       UINT _acp = GetACP();
-       LPCWSTR _lpw = 0;
-       LPCSTR  _lpa = 0;
-
-       return T2CA(str);
+       return convert(str, CP_ACP);
 }
 
 /**
@@ -37,8 +33,27 @@ LPCSTR ansiconvert_SystemCP(LPCTSTR str)
  */
 LPCSTR ansiconvert_ThreadCP(LPCTSTR str)
 {
-       USES_CONVERSION;
-       return T2CA(str);
+       return convert(str, CP_THREAD_ACP);
 }
 
-
+/**
+ * @brief Convert from Unicode to Ansi using given codepage.
+ * @param [in] str String to convert.
+ * @param [in] codepage Codepage to use in conversion.
+ * @return Ansi string.
+ */
+LPCSTR convert(LPCTSTR str, UINT codepage)
+{
+#ifndef UNICODE
+       return str;
+#else
+       int len = WideCharToMultiByte(codepage, 0, str, -1, 0, 0, 0, 0);
+       if (len)
+       {
+               char * ansi = (char *)malloc(len);
+               WideCharToMultiByte(codepage, 0, str, -1, ansi, len, NULL, NULL);
+               return ansi;
+       }
+       return NULL;
+#endif
+}
index cf4eba3..8d557b0 100644 (file)
@@ -87,7 +87,7 @@ bool DiffFileData::DoOpenFiles()
                // Actual paths are m_FileLocation[i].filepath
                // but these are often temporary files
                // Displayable (original) paths are m_sDisplayFilepath[i]
-               m_inf[i].name = strdup(ansiconvert_SystemCP(m_sDisplayFilepath[i]));
+               m_inf[i].name = ansiconvert_SystemCP(m_sDisplayFilepath[i]);
                if (m_inf[i].name == NULL)
                        return false;
 
index 7149830..6960147 100644 (file)
@@ -1202,8 +1202,8 @@ void CDiffWrapper::WritePatchFile(struct change * script, file_data * inf)
                path2 = m_s2File;
        replace_char(&*path1.begin(), '\\', '/');
        replace_char(&*path2.begin(), '\\', '/');
-       inf_patch[0].name = strdup(ansiconvert_SystemCP(path1.c_str()));
-       inf_patch[1].name = strdup(ansiconvert_SystemCP(path2.c_str()));
+       inf_patch[0].name = ansiconvert_SystemCP(path1.c_str());
+       inf_patch[1].name = ansiconvert_SystemCP(path2.c_str());
 
        outfile = NULL;
        if (!m_sPatchFile.IsEmpty())
index ce8c17d..15516e1 100644 (file)
@@ -236,6 +236,7 @@ void DirCmpReport::WriteString(LPCTSTR pszText)
                cchAhead -= cchLine;
        }
        m_pFile->Write(pchOctets, cchAhead);
+       free((void*)pchOctets);
 }
 
 /**