summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-10-31 16:45:22 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-10-31 16:45:22 +0300
commit05f5df51f72a7a597d606a9ffb95bbd326f06880 (patch)
tree0220915ee05b626ccdfa7d90a32cfdd9b01be6c5 /src
parent2a7ded5efc59c3c0c29c50e9a626e2f05530f3a4 (diff)
fix for occasional crashes in icolib
Diffstat (limited to 'src')
-rw-r--r--src/mir_app/src/IcoLib.h3
-rw-r--r--src/mir_app/src/icolib.cpp27
2 files changed, 25 insertions, 5 deletions
diff --git a/src/mir_app/src/IcoLib.h b/src/mir_app/src/IcoLib.h
index 9474295ac1..dd956e2162 100644
--- a/src/mir_app/src/IcoLib.h
+++ b/src/mir_app/src/IcoLib.h
@@ -24,6 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#pragma once
+#define ICOLIB_MAGIC 0xDEADBEEF
+
#define SECTIONPARAM_MAKE(index, level, flags) MAKELONG((index)&0xFFFF, MAKEWORD(level, flags))
#define SECTIONPARAM_INDEX(lparam) LOWORD(lparam)
#define SECTIONPARAM_LEVEL(lparam) LOBYTE(HIWORD(lparam))
@@ -78,6 +80,7 @@ public:
struct IcolibItem : public MZeroedObject
{
char* name;
+ DWORD signature = ICOLIB_MAGIC;
SectionItem* section;
int orderID;
wchar_t* description;
diff --git a/src/mir_app/src/icolib.cpp b/src/mir_app/src/icolib.cpp
index c5d86d2329..5411646a94 100644
--- a/src/mir_app/src/icolib.cpp
+++ b/src/mir_app/src/icolib.cpp
@@ -72,6 +72,22 @@ void __fastcall SafeDestroyIcon(HICON &hIcon)
// Helper functions to manage Icon resources
+static IcolibItem *Handle2Ptr(HANDLE hIcoLib)
+{
+ IcolibItem *p = (IcolibItem *)hIcoLib;
+ if (p == nullptr)
+ return nullptr;
+
+ __try {
+ if (p->signature != ICOLIB_MAGIC)
+ p = nullptr;
+ }
+ __except (EXCEPTION_EXECUTE_HANDLER) {
+ p = nullptr;
+ }
+ return p;
+}
+
static IconSourceFile* IconSourceFile_Get(const wchar_t *file, bool isPath)
{
if (!file)
@@ -581,9 +597,10 @@ MIR_APP_DLL(void) IcoLib_RemoveIcon(const char *pszIconName)
MIR_APP_DLL(void) IcoLib_RemoveIconByHandle(HANDLE hIcoLib)
{
- mir_cslock lck(csIconList);
+ auto *pItem = Handle2Ptr(hIcoLib);
- int i = iconList.getIndex((IcolibItem*)hIcoLib);
+ mir_cslock lck(csIconList);
+ int i = iconList.getIndex(pItem);
if (i != -1) {
iconList.remove(i);
delete iconList[i];
@@ -655,7 +672,7 @@ HICON IconItem_GetDefaultIcon(IcolibItem *item, bool big)
HICON IconItem_GetIcon(HANDLE hIcoLib, bool big)
{
- IcolibItem *item = (IcolibItem*)hIcoLib;
+ auto *item = Handle2Ptr(hIcoLib);
if (item == nullptr)
return nullptr;
@@ -724,11 +741,11 @@ MIR_APP_DLL(HANDLE) IcoLib_GetIconHandle(const char *pszIconName)
MIR_APP_DLL(HICON) IcoLib_GetIconByHandle(HANDLE hItem, bool big)
{
- if (hItem == nullptr)
+ IcolibItem *pi = Handle2Ptr(hItem);
+ if (pi == nullptr)
return nullptr;
mir_cslock lck(csIconList);
- IcolibItem *pi = (IcolibItem*)hItem;
if (iconList.getIndex(pi) != -1)
return IconItem_GetIcon(pi, big);