X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/18860312a42d941279c3b9b84b32775d8e80fddf..8a8997c3be3d3795a91ef0d977417b8d2681bb6f:/src/common/config.cpp

diff --git a/src/common/config.cpp b/src/common/config.cpp
index 4cc55702a7..f2d95677a4 100644
--- a/src/common/config.cpp
+++ b/src/common/config.cpp
@@ -246,7 +246,19 @@ wxConfigPathChanger::wxConfigPathChanger(const wxConfigBase *pContainer,
     {
         // do change the path
         m_bChanged = true;
-        m_strOldPath = m_pContainer->GetPath();
+
+        /* JACS: work around a memory bug that causes an assert
+           when using wxRegConfig, related to reference-counting.
+           Can be reproduced by removing (const wxChar*) below and
+           adding the following code to the config sample OnInit under
+           Windows:
+
+           pConfig->SetPath(wxT("MySettings"));
+           pConfig->SetPath(wxT(".."));
+           int value;
+           pConfig->Read(_T("MainWindowX"), & value);
+        */
+        m_strOldPath = (const wxChar*) m_pContainer->GetPath();
         if ( *m_strOldPath.c_str() != wxCONFIG_PATH_SEPARATOR )
           m_strOldPath += wxCONFIG_PATH_SEPARATOR;
         m_pContainer->SetPath(strPath);
@@ -384,7 +396,8 @@ wxString wxExpandEnvVars(const wxString& str)
 
       case '\\':
         // backslash can be used to suppress special meaning of % and $
-        if ( n != str.Len() && (str[n + 1] == wxT('%') || str[n + 1] == wxT('$')) ) {
+        if ( n != str.Len() - 1 &&
+                (str[n + 1] == wxT('%') || str[n + 1] == wxT('$')) ) {
           strResult += str[++n];
 
           break;