summaryrefslogtreecommitdiff
path: root/plugins/NotesAndReminders/src
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
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')
-rw-r--r--plugins/NotesAndReminders/src/miscutils.cpp147
-rw-r--r--plugins/NotesAndReminders/src/miscutils.h2
-rw-r--r--plugins/NotesAndReminders/src/notes.cpp30
3 files changed, 77 insertions, 102 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;
}
diff --git a/plugins/NotesAndReminders/src/miscutils.h b/plugins/NotesAndReminders/src/miscutils.h
index 104de5313c..41f7f5cddc 100644
--- a/plugins/NotesAndReminders/src/miscutils.h
+++ b/plugins/NotesAndReminders/src/miscutils.h
@@ -15,7 +15,7 @@ void DeleteSetting(HANDLE hContact,char *ModuleName,
char *SettingName);
void WriteSettingIntArray(HANDLE hContact,char *ModuleName,
char *SettingName,const int *Value, int Size);
-BOOL ReadSettingIntArray(HANDLE hContact,char *ModuleName,
+bool ReadSettingIntArray(HANDLE hContact,char *ModuleName,
char *SettingName,int *Value, int Size);
extern BOOL (WINAPI *MySetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD);
diff --git a/plugins/NotesAndReminders/src/notes.cpp b/plugins/NotesAndReminders/src/notes.cpp
index c65a5092ee..76f001cea1 100644
--- a/plugins/NotesAndReminders/src/notes.cpp
+++ b/plugins/NotesAndReminders/src/notes.cpp
@@ -155,7 +155,7 @@ static void InitNoteTitle(STICKYNOTE *TSN)
// append time if requested
if (g_NoteTitleTime)
{
- int n = strlen(TempStr);
+ int n = (int)strlen(TempStr);
TempStr[n++] = ' ';
TempStr[n] = 0;
@@ -879,9 +879,7 @@ static void JustSaveNotesEx(STICKYNOTE *pModified)
//
Value = (char*)malloc(SzT + 512);
-
- if (!Value)
- {
+ if (!Value) {
if (bDeleteTData)
SAFE_FREE((void**)&tData);
continue;
@@ -941,7 +939,7 @@ static void JustSaveNotesEx(STICKYNOTE *pModified)
{
// huston, we have a problem, strip some reminder text
n = 0xfffe;
- ValueName[0xffff] = 0;
+ Value[0xffff] = 0;
}
sprintf(ValueName, "NotesData%d", NotesCount - I - 1); // we do not reverse notes in DB
@@ -1052,7 +1050,7 @@ static void MeasureColorPresetMenuItem(HWND hdlg, LPMEASUREITEMSTRUCT lpMeasureI
HDC hdc = GetDC(hdlg);
LPTSTR lpsz = TranslateTS(clrPresets->szName);
SIZE sz;
- GetTextExtentPoint32(hdc, lpsz, _tcslen(lpsz), &sz);
+ GetTextExtentPoint32(hdc, lpsz, (int)_tcslen(lpsz), &sz);
ReleaseDC(hdlg, hdc);
lpMeasureItem->itemWidth = 50 + sz.cx;
@@ -1133,7 +1131,7 @@ static BOOL GetClipboardText_Title(char *pOut, int size)
if (*p == '\r' || *p == '\n')
{
*p = 0;
- n = strlen(pOut);
+ n = (int)strlen(pOut);
break;
}
else if (*p == '\t')
@@ -1768,7 +1766,7 @@ char* GetPreviewString(const char *lpsz)
while ( iswspace(*lpsz) )
lpsz++;
- l = strlen(lpsz);
+ l = (int)strlen(lpsz);
if (!l)
return "";
@@ -1833,7 +1831,7 @@ static void InitListView(HWND AHLV)
lvTIt.iItem = I;
lvTIt.iSubItem = 0;
lvTIt.pszText = (pNote->CustomTitle && pNote->title) ? pNote->title : S1;
- lvTIt.cchTextMax = strlen(S1);
+ lvTIt.cchTextMax = (int)strlen(S1);
ListView_InsertItem(AHLV,&lvTIt);
if (pNote->Visible)
@@ -1841,7 +1839,7 @@ static void InitListView(HWND AHLV)
lvTIt.iItem = I;
lvTIt.iSubItem = 1;
lvTIt.pszText = V;
- lvTIt.cchTextMax = strlen(lvTIt.pszText);
+ lvTIt.cchTextMax = (int)strlen(lvTIt.pszText);
ListView_SetItem(AHLV,&lvTIt);
}
@@ -1850,7 +1848,7 @@ static void InitListView(HWND AHLV)
lvTIt.iItem = I;
lvTIt.iSubItem = 2;
lvTIt.pszText = T;
- lvTIt.cchTextMax = strlen(lvTIt.pszText);
+ lvTIt.cchTextMax = (int)strlen(lvTIt.pszText);
ListView_SetItem(AHLV,&lvTIt);
}
@@ -1858,7 +1856,7 @@ static void InitListView(HWND AHLV)
lvTIt.iItem = I;
lvTIt.iSubItem = 3;
lvTIt.pszText = S;
- lvTIt.cchTextMax = strlen(S);
+ lvTIt.cchTextMax = (int)strlen(S);
ListView_SetItem(AHLV,&lvTIt);
I++;
@@ -1978,28 +1976,28 @@ INT_PTR CALLBACK DlgProcViewNotes(HWND Dialog,UINT Message,WPARAM wParam,LPARAM
S = TranslateT("Note text");
lvCol.pszText = S;
- lvCol.cchTextMax = _tcslen(S);
+ lvCol.cchTextMax = (int)_tcslen(S);
lvCol.cx = g_notesListColGeom[3];
ListView_InsertColumn(H,0,&lvCol);
lvCol.mask = LVCF_TEXT | LVCF_WIDTH;
S = TranslateT("T");
lvCol.pszText = S;
- lvCol.cchTextMax = _tcslen(S);
+ lvCol.cchTextMax = (int)_tcslen(S);
lvCol.cx = g_notesListColGeom[2];
ListView_InsertColumn(H,0,&lvCol);
lvCol.mask = LVCF_TEXT | LVCF_WIDTH;
S = TranslateT("V");
lvCol.pszText = S;
- lvCol.cchTextMax = strlen(S);
+ lvCol.cchTextMax = (int)strlen(S);
lvCol.cx = g_notesListColGeom[1];
ListView_InsertColumn(H,0,&lvCol);
lvCol.mask = LVCF_TEXT | LVCF_WIDTH;
S = TranslateT("Date/Title");
lvCol.pszText = S;
- lvCol.cchTextMax = _tcslen(S);
+ lvCol.cchTextMax = (int)_tcslen(S);
lvCol.cx = g_notesListColGeom[0];
ListView_InsertColumn(H,0,&lvCol);