summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/Db3x_mmap/src/dbsettings.cpp25
-rw-r--r--src/mir_core/src/utf.cpp2
2 files changed, 24 insertions, 3 deletions
diff --git a/plugins/Db3x_mmap/src/dbsettings.cpp b/plugins/Db3x_mmap/src/dbsettings.cpp
index bea58a8884..a1e89cb4d4 100644
--- a/plugins/Db3x_mmap/src/dbsettings.cpp
+++ b/plugins/Db3x_mmap/src/dbsettings.cpp
@@ -23,6 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
+#pragma warning(disable: 4701)
+
DWORD GetModuleNameOfs(const char *szName);
DBCachedContact* AddToCachedContactList(MCONTACT contactID, int index);
@@ -331,10 +333,28 @@ STDMETHODIMP_(BOOL) CDb3Mmap::GetContactSettingStr(MCONTACT contactID, LPCSTR sz
STDMETHODIMP_(BOOL) CDb3Mmap::GetContactSettingStatic(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv)
{
+ bool bNeedsWchars;
+ size_t cbSaved;
+
+ if (dbv->type == DBVT_WCHAR) { // there's no wchar_t strings in a database, we need conversion
+ cbSaved = dbv->cchVal-1;
+ dbv->cchVal *= sizeof(wchar_t); // extend a room for the utf8 string
+ dbv->type = DBVT_UTF8;
+ bNeedsWchars = true;
+ }
+ else bNeedsWchars = false;
+
if (GetContactSettingWorker(contactID, szModule, szSetting, dbv, 1))
return 1;
- if (dbv->type == DBVT_UTF8) {
+ if (bNeedsWchars) {
+ char *pBuf = NEWSTR_ALLOCA(dbv->pszVal);
+ if (Utf8toUcs2(pBuf, dbv->cchVal, dbv->pwszVal, cbSaved) < 0)
+ return 1;
+
+ dbv->pwszVal[cbSaved] = 0;
+ }
+ else if (dbv->type == DBVT_UTF8) {
mir_utf8decode(dbv->pszVal, NULL);
dbv->type = DBVT_ASCIIZ;
}
@@ -835,7 +855,8 @@ STDMETHODIMP_(BOOL) CDb3Mmap::EnumResidentSettings(DBMODULEENUMPROC pFunc, void
{
for (int i = 0; i < m_lResidentSettings.getCount(); i++) {
int ret = pFunc(m_lResidentSettings[i], 0, (LPARAM)pParam);
- if (ret) return ret;
+ if (ret)
+ return ret;
}
return 0;
}
diff --git a/src/mir_core/src/utf.cpp b/src/mir_core/src/utf.cpp
index b0240b28ec..d6050f81f4 100644
--- a/src/mir_core/src/utf.cpp
+++ b/src/mir_core/src/utf.cpp
@@ -207,7 +207,7 @@ static int Utf8toUcs2Len(const char *src, size_t srclen)
MIR_CORE_DLL(int) Utf8toUcs2(const char *src, size_t srclen, wchar_t *dst, size_t dstlen)
{
unsigned int res;
- const char *srcend = src + srclen;
+ const char *srcend = src + srclen; // including trailing zero
wchar_t *dstend = dst + dstlen;
while ((dst < dstend) && (src < srcend)) {