summaryrefslogtreecommitdiff
path: root/plugins/NotesAndReminders/src/miscutils.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-11-25 11:08:48 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-11-25 11:08:48 +0000
commit8f3a7e69c22035e10be8074b57c1fbd36699d37d (patch)
tree9e2572e7b6c2189389690ef1d3bba735a2b5b80c /plugins/NotesAndReminders/src/miscutils.cpp
parente027d86c08e0b00e33152f2541bf58875bad8a51 (diff)
memory corruption fix
git-svn-id: http://svn.miranda-ng.org/main/trunk@2476 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/NotesAndReminders/src/miscutils.cpp')
-rw-r--r--plugins/NotesAndReminders/src/miscutils.cpp147
1 files changed, 62 insertions, 85 deletions
diff --git a/plugins/NotesAndReminders/src/miscutils.cpp b/plugins/NotesAndReminders/src/miscutils.cpp
index b4de98404c..e592b94699 100644
--- a/plugins/NotesAndReminders/src/miscutils.cpp
+++ b/plugins/NotesAndReminders/src/miscutils.cpp
@@ -5,23 +5,22 @@ HANDLE (WINAPI *MyMonitorFromWindow)(HWND,DWORD);
BOOL (WINAPI *MyTzSpecificLocalTimeToSystemTime)(LPTIME_ZONE_INFORMATION,LPSYSTEMTIME,LPSYSTEMTIME);
BOOL (WINAPI *MySystemTimeToTzSpecificLocalTime)(LPTIME_ZONE_INFORMATION,LPSYSTEMTIME,LPSYSTEMTIME);
-
WORD ConvertHotKeyToControl(WORD HK)
{
- WORD R = 0;
- if ((HK & MOD_CONTROL) == MOD_CONTROL) R = R | HOTKEYF_CONTROL;
- if ((HK & MOD_ALT) == MOD_ALT) R = R | HOTKEYF_ALT;
- if ((HK & MOD_SHIFT) == MOD_SHIFT) R = R | HOTKEYF_SHIFT;
- return R;
+ WORD R = 0;
+ if ((HK & MOD_CONTROL) == MOD_CONTROL) R = R | HOTKEYF_CONTROL;
+ if ((HK & MOD_ALT) == MOD_ALT) R = R | HOTKEYF_ALT;
+ if ((HK & MOD_SHIFT) == MOD_SHIFT) R = R | HOTKEYF_SHIFT;
+ return R;
}
WORD ConvertControlToHotKey(WORD HK)
{
- WORD R = 0;
- if ((HK & HOTKEYF_CONTROL) == HOTKEYF_CONTROL) R = R | MOD_CONTROL;
- if ((HK & HOTKEYF_ALT) == HOTKEYF_ALT) R = R | MOD_ALT;
- if ((HK & HOTKEYF_SHIFT) == HOTKEYF_SHIFT) R = R | MOD_SHIFT;
- return R;
+ WORD R = 0;
+ if ((HK & HOTKEYF_CONTROL) == HOTKEYF_CONTROL) R = R | MOD_CONTROL;
+ if ((HK & HOTKEYF_ALT) == HOTKEYF_ALT) R = R | MOD_ALT;
+ if ((HK & HOTKEYF_SHIFT) == HOTKEYF_SHIFT) R = R | MOD_SHIFT;
+ return R;
}
void WriteSettingInt(HANDLE hContact,char *ModuleName,char *SettingName,int Value)
@@ -29,11 +28,11 @@ void WriteSettingInt(HANDLE hContact,char *ModuleName,char *SettingName,int Valu
DBCONTACTWRITESETTING cws = {0};
DBVARIANT dbv = {0};
dbv.type = DBVT_DWORD;
- dbv.dVal = Value;
+ dbv.dVal = Value;
cws.szModule = ModuleName;
- cws.szSetting = SettingName;
- cws.value = dbv;
- CallService(MS_DB_CONTACT_WRITESETTING,(DWORD)hContact,(DWORD)&cws);
+ cws.szSetting = SettingName;
+ cws.value = dbv;
+ CallService(MS_DB_CONTACT_WRITESETTING, (WPARAM)hContact, (DWORD)&cws);
}
int ReadSettingInt(HANDLE hContact,char *ModuleName,char *SettingName,int Default)
@@ -41,13 +40,13 @@ int ReadSettingInt(HANDLE hContact,char *ModuleName,char *SettingName,int Defaul
DBCONTACTGETSETTING cws = {0};
DBVARIANT dbv = {0};
dbv.type = DBVT_DWORD;
- dbv.dVal = Default;
+ dbv.dVal = Default;
cws.szModule = ModuleName;
- cws.szSetting = SettingName;
+ cws.szSetting = SettingName;
cws.pValue = &dbv;
- if (CallService(MS_DB_CONTACT_GETSETTING,(DWORD)hContact,(DWORD)&cws))
+ if (CallService(MS_DB_CONTACT_GETSETTING,(DWORD)hContact,(DWORD)&cws))
return Default;
- else
+ else
return dbv.dVal;
}
@@ -60,7 +59,7 @@ void DeleteSetting(HANDLE hContact,char *ModuleName,char *SettingName)
CallService(MS_DB_CONTACT_DELETESETTING,(DWORD)hContact,(DWORD)&dbcgs);
}
-void FreeSettingBlob(WORD pSize,void * pbBlob)
+void FreeSettingBlob(WORD pSize,void *pbBlob)
{
DBVARIANT dbv = {0};
dbv.type = DBVT_BLOB;
@@ -87,17 +86,14 @@ void ReadSettingBlob(HANDLE hContact, char *ModuleName, char *SettingName, WORD
DBCONTACTGETSETTING cgs = {0};
DBVARIANT dbv = {0};
dbv.type = DBVT_BLOB;
-// dbv.cpbVal = (LOBYTE(pSize) | HIBYTE((BYTE)pbBlob)); // this is not used anyway
cgs.szModule = ModuleName;
cgs.szSetting = SettingName;
cgs.pValue = &dbv;
- if (CallService(MS_DB_CONTACT_GETSETTING,(DWORD)hContact,(DWORD)&cgs))
- {
- pSize = 0; // tohle asi ve 4.2 neni
- pbBlob = NULL;
+ if ( CallService(MS_DB_CONTACT_GETSETTING,(DWORD)hContact,(DWORD)&cgs)) {
+ *pSize = 0;
+ *pbBlob = NULL;
}
- else
- {
+ else {
*pSize = LOWORD(dbv.cpbVal);
*pbBlob = (int*)dbv.pbVal;
}
@@ -108,36 +104,29 @@ void WriteSettingIntArray(HANDLE hContact,char *ModuleName,char *SettingName,con
WriteSettingBlob(hContact,ModuleName,SettingName,sizeof(int)*Size,(void*)Value);
}
-BOOL ReadSettingIntArray(HANDLE hContact,char *ModuleName,char *SettingName,int *Value, int Size)
+bool ReadSettingIntArray(HANDLE hContact,char *ModuleName,char *SettingName,int *Value, int Size)
{
WORD sz = 4096;
int *pData;
- BOOL bResult;
-
ReadSettingBlob(hContact, ModuleName, SettingName, &sz, (void**)&pData);
-
if (!pData)
- return FALSE;
+ return false;
- bResult = FALSE;
+ bool bResult = false;
- if (sz == sizeof(int)*Size)
- {
+ if (sz == sizeof(int)*Size) {
memcpy(Value, pData, sizeof(int)*Size);
- bResult = TRUE;
+ bResult = true;
}
FreeSettingBlob(sz,pData);
-
return bResult;
}
void TreeAdd(TREEELEMENT **root, void *Data)
{
- TREEELEMENT *NTE;
- NTE = (TREEELEMENT*)malloc(sizeof(TREEELEMENT));
- if (NTE)
- {
+ TREEELEMENT *NTE = (TREEELEMENT*)malloc(sizeof(TREEELEMENT));
+ if (NTE) {
NTE->ptrdata = Data;
NTE->next = *root;
*root = NTE;
@@ -146,17 +135,13 @@ void TreeAdd(TREEELEMENT **root, void *Data)
void TreeAddSorted(TREEELEMENT **root,void *Data,int (*CompareCb)(TREEELEMENT*,TREEELEMENT*))
{
- TREEELEMENT *TTE,*Prev;
- TREEELEMENT *NTE;
-
- if (!*root)
- {
+ if (!*root) {
// list empty, just add normally
TreeAdd(root,Data);
return;
}
- NTE = (TREEELEMENT*)malloc(sizeof(TREEELEMENT));
+ TREEELEMENT *NTE = (TREEELEMENT*)malloc(sizeof(TREEELEMENT));
if (!NTE)
return;
@@ -165,20 +150,16 @@ void TreeAddSorted(TREEELEMENT **root,void *Data,int (*CompareCb)(TREEELEMENT*,T
// insert sorted
- Prev = NULL;
- TTE = *root;
+ TREEELEMENT *Prev = NULL;
+ TREEELEMENT *TTE = *root;
- while (TTE)
- {
- if (CompareCb(NTE, TTE) < 0)
- {
- if (Prev)
- {
+ while (TTE) {
+ if (CompareCb(NTE, TTE) < 0) {
+ if (Prev) {
Prev->next = NTE;
NTE->next = TTE;
}
- else
- {
+ else {
// first in list
NTE->next = TTE;
*root = NTE;
@@ -194,18 +175,17 @@ void TreeAddSorted(TREEELEMENT **root,void *Data,int (*CompareCb)(TREEELEMENT*,T
Prev->next = NTE;
}
-void TreeDelete(TREEELEMENT **root,void *Item)
+void TreeDelete(TREEELEMENT **root,void *iItem)
{
- TREEELEMENT *TTE,*Prev = NULL;
- TTE = *root;
- if (!TTE) return;
- while ((TTE) && (TTE->ptrdata != Item))
- {
+ TREEELEMENT *TTE = *root, *Prev = NULL;
+ if (!TTE)
+ return;
+
+ while ((TTE) && (TTE->ptrdata != iItem)) {
Prev = TTE;
TTE = (TREEELEMENT*)TTE->next;
}
- if (TTE)
- {
+ if (TTE) {
if (Prev)
Prev->next = TTE->next;
else
@@ -214,33 +194,30 @@ void TreeDelete(TREEELEMENT **root,void *Item)
}
}
-void *TreeGetAt(TREEELEMENT *root,int Item)
+void *TreeGetAt(TREEELEMENT *root, int iItem)
{
- TREEELEMENT *TTE;
- int I = 0;
- if (!root) return NULL;
- TTE = root;
- while ((TTE) && (I != Item))
- {
+ if (!root)
+ return NULL;
+
+ TREEELEMENT *TTE = root;
+ int i = 0;
+ while ((TTE) && (i != iItem)) {
TTE = (TREEELEMENT*)TTE->next;
- I++;
+ i++;
}
- if (!TTE)
- return NULL;
- else
- return TTE->ptrdata;
+ return (!TTE) ? NULL : TTE->ptrdata;
}
int TreeGetCount(TREEELEMENT *root)
{
- int I = 0;
- TREEELEMENT *TTE;
- if (!root) return 0;
- TTE = root;
- while (TTE)
- {
+ if (!root)
+ return 0;
+
+ int i = 0;
+ TREEELEMENT *TTE = root;
+ while (TTE) {
TTE = (TREEELEMENT*)TTE->next;
- I++;
+ i++;
}
- return I;
+ return i;
}