]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/intl.cpp
Wait() doesn't cancel the thread any longer
[wxWidgets.git] / src / common / intl.cpp
index 684c9a5f2516b0e2418017183a1642a6c51f2eb0..b8d28fdb0d4ccbc223659cbbb7c307869ecd59fd 100644 (file)
@@ -141,6 +141,7 @@ static inline wxString ExtractNotLang(const wxString& langFull)
 #endif // __UNIX__
 
 
+
 // ----------------------------------------------------------------------------
 // wxMsgCatalogFile corresponds to one disk-file message catalog.
 //
@@ -187,21 +188,37 @@ private:
     // all data is stored here, NULL if no data loaded
     size_t8 *m_pData;
 
+    // amount of memory pointed to by m_pData.
+    size_t32 m_nSize;
+
     // data description
     size_t32          m_numStrings;   // number of strings in this domain
     wxMsgTableEntry  *m_pOrigTable,   // pointer to original   strings
                      *m_pTransTable;  //            translated
 
-    const char *StringAtOfs(wxMsgTableEntry *pTable, size_t32 index) const
-      { return (const char *)(m_pData + Swap(pTable[index].ofsString)); }
+    // swap the 2 halves of 32 bit integer if needed
+    size_t32 Swap(size_t32 ui) const
+    {
+          return m_bSwapped ? (ui << 24) | ((ui & 0xff00) << 8) |
+                              ((ui >> 8) & 0xff00) | (ui >> 24)
+                            : ui;
+    }
 
-    wxString GetCharset() const;
+    const char *StringAtOfs(wxMsgTableEntry *pTable, size_t32 n) const
+    {
+        const wxMsgTableEntry * const ent = pTable + n;
 
-    // utility functions
-      // big<->little endian
-    inline size_t32 Swap(size_t32 ui) const;
+        // this check could fail for a corrupt message catalog
+        size_t32 ofsString = Swap(ent->ofsString);
+        if ( ofsString + Swap(ent->nLen) > m_nSize)
+            return NULL;
 
-    bool          m_bSwapped;   // wrong endianness?
+        return (const char *)(m_pData + ofsString);
+    }
+
+    wxString GetCharset() const;
+
+    bool m_bSwapped;   // wrong endianness?
 
     DECLARE_NO_COPY_CLASS(wxMsgCatalogFile)
 };
@@ -249,22 +266,15 @@ static wxArrayString s_searchPrefixes;
 // wxMsgCatalogFile class
 // ----------------------------------------------------------------------------
 
-// swap the 2 halves of 32 bit integer if needed
-size_t32 wxMsgCatalogFile::Swap(size_t32 ui) const
-{
-  return m_bSwapped ? (ui << 24) | ((ui & 0xff00) << 8) |
-                      ((ui >> 8) & 0xff00) | (ui >> 24)
-                    : ui;
-}
-
 wxMsgCatalogFile::wxMsgCatalogFile()
 {
-  m_pData = NULL;
+    m_pData = NULL;
+    m_nSize = 0;
 }
 
 wxMsgCatalogFile::~wxMsgCatalogFile()
 {
-  wxDELETEA(m_pData);
+    wxDELETEA(m_pData);
 }
 
 // return all directories to search for given prefix
@@ -413,6 +423,7 @@ bool wxMsgCatalogFile::Load(const wxChar *szDirPrefix, const wxChar *szName0)
                    Swap(pHeader->ofsOrigTable));
   m_pTransTable = (wxMsgTableEntry *)(m_pData +
                    Swap(pHeader->ofsTransTable));
+  m_nSize = nSize;
 
   // everything is fine
   return TRUE;
@@ -644,6 +655,23 @@ bool wxLocale::Init(const wxChar *szName,
   return bOk;
 }
 
+
+#if defined(__UNIX__) && wxUSE_UNICODE
+static wxWCharBuffer wxSetlocaleTryUTF(int c, const wxChar *lc)
+{
+    wxMB2WXbuf l = wxSetlocale(c, lc);
+    if ( lc && lc[0] != 0 && !l )
+    {
+       wxString buf(lc);
+       buf += wxT(".utf8");
+       l = wxSetlocale(c, buf.c_str());
+    }
+    return l;
+}
+#else
+#define wxSetlocaleTryUTF(c, lc)  wxSetlocale(c, lc)
+#endif
+
 bool wxLocale::Init(int language, int flags)
 {
     int lang = language;
@@ -679,12 +707,12 @@ bool wxLocale::Init(int language, int flags)
     else
         locale = info->CanonicalName;
 
-    wxMB2WXbuf retloc = wxSetlocale(LC_ALL, locale);
+    wxMB2WXbuf retloc = wxSetlocaleTryUTF(LC_ALL, locale);
 
     if ( !retloc )
     {
         // Some C libraries don't like xx_YY form and require xx only
-        retloc = wxSetlocale(LC_ALL, locale.Mid(0,2));
+        retloc = wxSetlocaleTryUTF(LC_ALL, locale.Mid(0,2));
     }
     if ( !retloc )
     {
@@ -702,13 +730,13 @@ bool wxLocale::Init(int language, int flags)
         else if (mid == wxT("nn"))
             locale = wxT("no_NY");
 
-        retloc = wxSetlocale(LC_ALL, locale);
+        retloc = wxSetlocaleTryUTF(LC_ALL, locale);
     }
     if ( !retloc )
     {
         // (This time, we changed locale in previous if-branch, so try again.)
         // Some C libraries don't like xx_YY form and require xx only
-        retloc = wxSetlocale(LC_ALL, locale.Mid(0,2));
+        retloc = wxSetlocaleTryUTF(LC_ALL, locale.Mid(0,2));
     }
     if ( !retloc )
     {